JQuery: How to get the number of elements in the list?

.size function used to get the size.

Example :

Code:


<div id="id_grpList" style="display:none">
Groups:
<ul>
<li id="1">Friends</li>

<li id="2">Family</li>

<li id="3">Colleagues</li>

<li id="4">Relatives</li>

</ul>
</div>

<div id="id_jobSite" style="display:none">
US Job Sites:
<ul>
<li>monster <li>indeed <li>dice </ul>
<ul id="id_newsPaper">
</ul>
</div>




<script>
//if the group have list of elements then display that grpList div
if($("#id_grpList li").size()>0) {
$('#id_grpList').show();
}
//if news paper have list then show the jobSite div
if($("#id_newsPaper li").size()>0) {
$('#id_newsPaper').show();
}