Skip to main content

Bug Tracker

Side navigation

#4793 closed bug (invalid)

Opened June 20, 2009 11:39AM UTC

Closed October 03, 2009 01:15AM UTC

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 (1)

Changed October 03, 2009 01:15AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

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