Skip to content
Permalink
Browse files

Handle child selectors in particular - away from the selector engine.…

… Fixes #7029.
  • Loading branch information
jeresig committed Sep 28, 2010
1 parent 873c284 commit f1f6bc3ec43d86f5b2a0c2b8bf711a2d35930717
Showing with 9 additions and 1 deletion.
  1. +6 −0 src/traversing.js
  2. +3 −1 test/unit/traversing.js
@@ -4,11 +4,17 @@ var runtil = /Until$/,
rparentsprev = /^(?:parents|prevUntil|prevAll)/,
// Note: This RegExp should be improved, or likely pulled from Sizzle
rmultiselector = /,/,
rchild = /^\s*>/,
isSimple = /^.[^:#\[\.,]*$/,
slice = Array.prototype.slice;

jQuery.fn.extend({
find: function( selector ) {
// Handle "> div" child selectors and pass them to .children()
if ( typeof selector === "string" && rchild.test( selector ) ) {
return this.children( selector.replace( rchild, "" ) );
}

var ret = this.pushStack( "", "find", selector ), length = 0;

for ( var i = 0, l = this.length; i < l; i++ ) {
@@ -1,12 +1,14 @@
module("traversing");

test("find(String)", function() {
expect(2);
expect(3);
equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );

// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );

same( jQuery("#main").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" );
});

test("is(String)", function() {

5 comments on commit f1f6bc3

@jdalton

This comment has been minimized.

Copy link
Member

jdalton replied Sep 29, 2010

What's the reason for the switch ?

@jeresig

This comment has been minimized.

Copy link
Member Author

jeresig replied Sep 29, 2010

We're deprecating the >-prefixed style of selectors (removing it from Sizzle).

@ghost

This comment has been minimized.

Copy link

ghost replied Sep 29, 2010

That stinks. Not part of querySelectorAll, but damned useful.

@leeoniya

This comment has been minimized.

Copy link

leeoniya replied Sep 29, 2010

thus leaving

$("#main").children("div")
yes??

EDIT: nvm...durrr

@jeresig

This comment has been minimized.

Copy link
Member Author

jeresig replied Sep 29, 2010

@jupiterjs: Not sure what what the problem is - we're still supporting the > prefix in .find() - which is used everywhere in jQuery - but the > prefix isn't part of selector engines and we need to stop using it. Note that we've been doing similar for other parts of the selector engine as well (e.g. :last -> .last(), :eq -> .eq(), etc.)

Please sign in to comment.
You can’t perform that action at this time.