How to count number of elements in jquery

Counting elements is sometimes very important task so here is the simple tutorial of <strong>counting number of elements in jquery.</strong> You can count any elements but the elements must be within the parent container.

HTML

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<a href="#" id="countitems">Count Number of List Items in following List</a>
<ul id="list">
	<li>one</li>
    <li>two</li>
    <li>three</li>
    <li>four</li>
</ul>

JavaScript

$(document).ready(function(e) {
        $('#countitems').click(function(){
				$no_of_items=$('#list li').length;
				alert($no_of_items);
			});
    });