Created
November 13, 2009 02:58
-
-
Save cowboy/233550 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<title>oops?</title> | |
<script type="text/javascript" src="http://benalman.com/code/jquery/dist/jquery.js"></script> | |
<script type="text/javascript" language="javascript"> | |
<!-- | |
$(function(){ | |
var html = '' | |
+ '<div class="d">' | |
+ ' <h2 class="i0"/>' | |
+ ' <p class="i1">' | |
+ ' <b class="j1">' | |
+ ' <i class="k1"/>' | |
+ ' <\/b>' | |
+ ' <\/p>' | |
+ ' <p class="i2"/>' | |
+ ' <p class="i3"/>' | |
+ ' <h3 class="i4"/>' | |
+ ' <h2 class="i5"/>' | |
+ ' <p class="i6"/>' | |
+ ' <p class="i7"/>' | |
+ ' <p class="i8"/>' | |
+ ' <h3 class="i9"/>' | |
+ '<\/div>'; | |
function log( title, elems ) { | |
var elems_str = elems | |
? ' - ' + $.map( elems.get(), function(v,i){ | |
return v.nodeName + '.' + v.className; | |
}).join(', ') | |
: ''; | |
$('#pre2').append( title + elems_str + "\r\n" ); | |
} | |
function test(){ | |
var elems = $( html ); | |
log( $.fn.jquery ); | |
log( ':first nextAll', elems.children(':first').nextAll() ); | |
log( 'h2 nextAll ', elems.children('h2').nextAll() ); | |
log( ':last prevAll ', elems.children(':last').prevAll() ); | |
log( 'h3 prevAll ', elems.children('h3').prevAll() ); | |
log( 'i parents ', elems.find('i').parents() ); | |
log( 'i,b parents ', elems.find('i,b').parents() ); | |
}; | |
$('#pre1').text( "Given this HTML structure:\n\n" + html.replace( />/g, ">\n" ) + "\n" ); | |
test(); | |
log(''); | |
$.getScript( 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js', function(){ | |
test(); | |
}); | |
}); // END CLOSURE | |
//--> | |
</script> | |
</head> | |
<body> | |
<pre id="pre1"></pre> | |
<pre id="pre2"> | |
My observations: | |
1.4pre | |
:first nextAll - P.i1, P.i2, P.i3, H3.i4, H2.i5, P.i6, P.i7, P.i8, H3.i9 - correct | |
h2 nextAll - P.i1, P.i2, P.i3, H3.i4, H2.i5, P.i6, P.i7, P.i8, H3.i9 - correct | |
:last prevAll - P.i8, P.i7, P.i6, H2.i5, H3.i4, P.i3, P.i2, P.i1, H2.i0 - correct | |
h3 prevAll - H2.i0, P.i1, P.i2, P.i3, H3.i4, H2.i5, P.i6, P.i7, P.i8 - NOT CORRECT | |
i parents - B.j1, P.i1, DIV.d - correct | |
i,b parents - B.j1, P.i1, DIV.d - correct | |
1.3.2 | |
:first nextAll - P.i1, P.i2, P.i3, H3.i4, H2.i5, P.i6, P.i7, P.i8, H3.i9 - correct | |
h2 nextAll - P.i1, P.i2, P.i3, H3.i4, H2.i5, P.i6, P.i7, P.i8, H3.i9 - correct | |
:last prevAll - P.i8, P.i7, P.i6, H2.i5, H3.i4, P.i3, P.i2, P.i1, H2.i0 - correct | |
h3 prevAll - P.i3, P.i2, P.i1, H2.i0, P.i8, P.i7, P.i6, H2.i5, H3.i4 - NOT CORRECT | |
i parents - B.j1, P.i1, DIV.d - correct | |
i,b parents - B.j1, P.i1, DIV.d - correct | |
Live tests: | |
</pre> | |
It might be as simple as changing <a href="http://github.com/jquery/jquery/blob/master/src/traversing.js#L138">this line</a> to: | |
<pre> | |
if ( ( name === "parents" || name === "prevAll" ) && this.length > 1 ) { | |
</pre> | |
- Ben | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment