Side navigation
#766 closed bug (fixed)
Opened January 09, 2007 12:21AM UTC
Closed January 09, 2007 03:46PM UTC
Last modified June 19, 2007 06:51AM UTC
$(SELECTOR).next() and $(SELECTOR).prev() are not working
| Reported by: | himynameiznate | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.1a |
| Component: | core | Version: | 1.1a |
| Keywords: | siblings | Cc: | |
| Blocked by: | Blocking: |
Description
When looking for siblings in 1.1a, the .next() and .prev() functions do not return anything, even when there are clearly siblings.
Example code:
<p id="first">First paragraph</p>[[BR]]
<p id="second">Second paragraph</p>[[BR]]
<p id="third">Third paragraph</p>[[BR]]
<script>
console.log($('#second')); // Shows second paragraph
console.log($('#second').prev()); //Displays second, should show first paragraph
console.log($('#second').next()); //Displays second, should show third paragraph
</script>
Attachments (0)
Change History (3)
Changed January 09, 2007 01:17AM UTC by comment:1
Changed January 09, 2007 01:54AM UTC by comment:2
My code actually breaks the adjacent sibling selector, so I don't recommend it.
The existing code seems to work for everything except .next and .prev. For the life of me, I can't figure out why cur = cur[dir] doesnt get set in the for loop when using those functions...
Changed January 09, 2007 03:46PM UTC by comment:3
| resolution: | → fixed |
|---|---|
| status: | new → closed |
Fixed in SVN rev 956.
After looking at the code, it appears that changing jQuery.nth's function definition to the following code appears to fix it. The for-loop and the cur[dir] assignment seems to have been broken.
This may have some unknown impact on the selectors nth-child, first-child, last-child, but I will test those right now.
nth: function(cur,result,dir){ result = result || 1; var num = 0; while(cur){ cur = cur[dir]; num += ( cur.nodeType == 1 ) ? 1 : 0; if ( (num == result) || (result == "even" && num % 2 == 0 && num > 1) || (result == "odd" && num % 2 == 1) ) return cur; } }