Ticket #4793 (closed bug: invalid)
Selector not working as expected
| Reported by: | imdeepakpathak | Owned by: | john |
|---|---|---|---|
| Priority: | critical | Milestone: | 1.4 |
| Component: | selector | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I am using the following selector:
<script type="text/javascript">
$(document).ready(function() { $("p:odd").addClass("Class2"); $("p:even").addClass("Class1"); });
</script>
The CSS class used are:
.Class1 {
background-color:Red; color:Yellow;
}
.Class2 {
background-color: Green; color: White;
}
The HTML on which I am trying to run the above jQuery code is(the code is shortened for brevity):
<html> <body>
<form id="form1" runat="server"> <div> <p> This is an Odd paragraph</p> <br /> <p> This is an Even paragraph</p> <br /> <p> This is an Odd paragraph</p> <br /> <p> This is an Even paragraph</p> <br /> <p> This is an Odd paragraph</p> <br /> </div> </form>
</body> </html>
The above code should use the CSS class named "Class1" for all the "Even" paragraphs and "Class2" for all "Odd" paragraphs, whereas in my case it is showing an exactly opposite behavior. It is showing all "Even" paragaphs by using CSS class named "Class1" and for all "Odd" paragraphs the styling is used from "Class2".
Please advice.
Attachments
Change History
Changed 4 years ago by imdeepakpathak
-
attachment
PracticejQueryinASPNETApp.rar
added
comment:1 Changed 4 years ago by dmethvin
- Status changed from new to closed
- Resolution set to invalid
Note that :odd and :even number from 0, not 1.
http://docs.jquery.com/Selectors/even
The :nth-child selector numbers from 1.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Files related to the bug.