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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 191
    Comment on it

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

    The :odd selector will choose all those components which have odd index i.e 1,2,5 etc.

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

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

    Below is the html code for finding odd 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>
        <button id="btn">Click to see the effect</button> 

    Below is the jQuery code :-

        $( "tr:odd" ).css( "background-color", "green" );

    working demo:-

 0 Comment(s)

Sign In

Sign up using

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: