Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#766 closed bug (fixed)

$(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>

Change History (3)

comment:1 Changed 13 years ago by himynameizna

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;
			}
	}

comment:2 Changed 13 years ago by himynameizna

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...

comment:3 Changed 13 years ago by john

Resolution: fixed
Status: newclosed

Fixed in SVN rev 956.

Note: See TracTickets for help on using tickets.