Thursday, February 16, 2012

Javascript/jquery count li elements inside ul

Below is the script with which you can get the count of li present in ul..


Html::

<ul id="myulid">
  <li>List Item1</li>
  <li>List Item2</li>
  <li>List Item3</li>
  <li>List Item4</li>
  <li>List Item5</li>
</ul>

Java Script:: 


<script type="text/javascript">
var myul = document.getElementById('myulid');
var liCount= myul.getElementsByTagName('li').length;
alert(liCount);
</script>


Hope this helps...

Monday, February 6, 2012

How to call code behind server method from a client side javascript

In this post we will see how to call a server side function from JavaScript.
 

HTML::
<div style="visibility: hidden">
<asp:Button ID="mybtn" runat="Server" onclick="mybtn_Click" />
</div>

Java Script::
var hiddenMyBtn = document.getElementById('<%= mybtn.ClientID %>');
hiddenMyBtn.click();

Server side code::
protected void mybtn_Click(object sender, EventArgs e)
{
//Do your stuff
}


Hope this helps...


Popular Posts