Bug Tracker

Opened 14 years ago

Closed 13 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:


I am using the following selector:

<script type="text/javascript">

$(document).ready(function() { $("p:odd").addClass("Class2"); $("p:even").addClass("Class1"); });


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)

PracticejQueryinASPNETApp.rar (33.8 KB) - added by imdeepakpathak 14 years ago.
Files related to the bug.

Download all attachments as: .zip

Change History (2)

Changed 14 years ago by imdeepakpathak

Files related to the bug.

comment:1 Changed 13 years ago by dmethvin

Resolution: invalid
Status: newclosed

Note that :odd and :even number from 0, not 1.


The :nth-child selector numbers from 1.


Note: See TracTickets for help on using tickets.