Problem with input:text with filter
Hi,
I am working on learning more about jQuery selectors. I have a simple page and I wrote two simple scripts to change the colors of the odd/even text input objects.
Here's the HTML and JS code:
Selectors.html
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>jQuery Selectors</title>
-
- <script type="text/javascript" src="/resources/jquery/jquery.1.11.1.min.js"></script>
- <script type="text/javascript" src="selectors.js"></script>
- </head>
- <body>
- <table>
- <tr>
- <td>Name</td>
- <td><input type="text" id="txtName" /></td>
- <td><input type="button" id="cmdName" value="SetName" onclick="setValueName();"/></td>
- </tr>
- <tr>
- <td>Date & Time</td>
- <td><input type="text" id="txtDateTime" /></td>
- <td><input type="button" id="cmdDateTime" value="SetDateTime" onclick="setValueDateTime();"/></td>
- </tr>
- <tr>
- <td>Name</td>
- <td><input type="text" id="txtName2" /></td>
- <td><input type="button" id="cmdSetOdd" value="Set Odd Colors" onclick="setOddColor();"/></td>
- </tr>
- <tr>
- <td>Date & Time</td>
- <td><input type="text" id="txtDateTime2" /></td>
- <td><input type="button" id="cmdSetEven" value="Set Even Colors" onclick="setEvenColor();"/></td>
- </tr>
-
- </table>
- </body>
- </html>
Selectors.js
- function setValueName(){
- $('#txtName').val('Menachem Bazian');
- }
- function setValueDateTime(){
- var dDate = new Date($.now());
- $('#txtDateTime').val(dDate);
- }
- function setOddColor(){
- $('input:text:odd').css("background-color", "#C0C0C0");
- }
- function setEvenColor(){
- $('input:text:even').css("background-color", "blue");
- }
Here's the problem. When I click on the Even button, it is changing the color of the first and third text inputs. When I click on the Odd button, it does the second and fourth.
What am I doing wrong?
Thanks