JQuery size () method is used to count DOM element’s by specifying matched elements. In this demo I am try to show you, how we can count specified DOM element s on the matched condition. In this demo multiple <option> element is define in <select> element and I want to count <option> element as a total number of cities.

Syntax :$( “document”).size ();

<title>JQuery size method</title>
    <script type="text/javascript" src="jquery.min.js    </script>
    <script type="text/javascript">
        var x;
        $(document).ready(function()        {
                x = $("option").size();//size function will count <option> element that contained cities name where x variable will store size of <option> element that define in <select> element
                alert('Total Cities...' + x.toString());//this line will show total number of cities
        JQuery size method</h2>
    <table width="200">
    <td align="center">
    City List
                    Total Cities</button>

JQuery size method

If I will click on button we will get total number of cities as shown below:


JQuery size method

  Modified On Sep-07-2019 12:12:05 AM

Leave Comment