jQuery Selectors: Applying indexed selector to table row

This entry is part 31 of 33 in the series jQuery Selectors

$(‘tr:eq(4)’)

As in the earlier example, the index selector could be applied to selecting a particular row in a table.

<!DOCTYPE html>
<html>
<head lang='en'>
    <meta charset='UTF-8'>
    <title>HTML Table</title>
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
    <script>
        $(function () {
            $('tr:eq(4)').css('background-color', 'lightgray');
        });
    </script>
</head>
<table border='1'>
    <tr>
        <th>ID</th>
        <th>artiste</th>
        <th>album</th>
        <th>year</th>
    </tr>
    <tr>
        <td>1</td>
        <td>Rod Stewart</td>
        <td>Maggie May</td>
        <td>1973</td>
    </tr>
    <tr>
        <td>2</td>
        <td>New Order</td>
        <td>Substance</td>
        <td>1987</td>
    </tr>
    <tr>
        <td>3</td>
        <td>Nirvana</td>
        <td>Smell Like Teen Spirit</td>
        <td>1992</td>
    </tr>
    <tr>
        <td>4</td>
        <td>Rod Stewart</td>
        <td>Out Of Order</td>
        <td>1988</td>
    </tr>
</table>
</body>
</html>

Series Navigation<< jQuery Selectors: Selects element at specific zero-based index
jQuery Selectors: The greater then gt selector >>