Select even table elements?
Hello everyone:
I am doing a exercise to select even
table elements, then change the background color and font color of the elements.
To me the code should highlight the content in event number of <td> tag (e.g. Name and
Approx. Location)
Could someone explain to me why this happened and what change shall I make, so the code will highlight the content
in the even number of the <td> tags
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html>
-
- <head>
- <title>hello world</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" ></script>
- <script language="JavaScript" type="text/javascript">
- <!--
-
- $(document).ready(function(){
- $('#celebs tr td:even').css('background-color', '#dddddd');
- $('#celebs tr td:even').css('color', '#666');
- });
-
- //-->
- </script>
- </head>
- <body>
- <table class="data" id="celebs">
-
- <tr>
- <td>ID</td>
- <td>NAME</td>
- <td>OCCUPATION</td>
- <td>Approx. Location</td>
- <td>Price</td>
- </tr>
- </table>
- </body>
- </html>