Jquery count number of spesific class and get spesific value index

<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
        <script type="text/javascript">

            $(document).ready(function() {
                alert( $(".red:eq(2)").html() ); //get spesific index from spesific class
		lert( $(".red").length );// Count number spesific index
            });

        </script>
    </head>
    <body>

        <p class="red">Test</p>
        <p class="red">Test1</p>
        <p class="red">Test2</p>
        <p class="red">Test3</p>
        <p class="reds">Test</p>
    </body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: