Opened 14 years ago
Closed 14 years ago
#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: | ||
Blocked by: | Blocking: |
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 (1)
Change History (2)
Changed 14 years ago by
Attachment: | PracticejQueryinASPNETApp.rar added |
---|
comment:1 Changed 14 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Note that :odd and :even number from 0, not 1.
http://docs.jquery.com/Selectors/even
The :nth-child selector numbers from 1.
Files related to the bug.