Bug Tracker

Modify

Ticket #4793 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

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

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

Change History

Changed 4 years ago by imdeepakpathak

Files related to the bug.

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.

 http://docs.jquery.com/Selectors/nthChild#index

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.