Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to finds even table rows using jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 411
    Comment on it

    If you want to find even number of table rows then it's not a difficult task now, we can do this easily with the help of jQuery :even selector.

    The :even selector will choose all those components which have even index i.e 0,2,4,6 etc.

    Most of the time we have to use :even selector  together with another selector for choosing those  component which have even index .

    In below example we are finding all table rows which have even index value with the help of :even selector and then making their background  grey.

    Below is the html code for finding even number of table rows  :-

    <table border="1">
    <tr><td> Index value 0</td></tr>
    <tr><td> Index value 1</td></tr>
    <tr><td> Index value 2</td></tr>
    <tr><td> Index value 3</td></tr>
    <tr><td> Index value 4</td></tr>
    <tr><td> Index value 5</td></tr>
    <tr><td> Index value 6</td></tr>
    </table>
    <button id="btn">Click to see the effect</button> 

    Below is the jQuery code :-

    $('#btn').click(function(){ 
    $( "tr:even" ).css( "background-color", "grey" );
    });

    Working demo:- https://jsfiddle.net/bqp9hje5/6/

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: