Skip to content

Commit

Permalink
Handle child selectors in particular - away from the selector engine.…
Browse files Browse the repository at this point in the history
… Fixes #7029.
  • Loading branch information
jeresig committed Sep 28, 2010
1 parent 873c284 commit f1f6bc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/traversing.js
Expand Up @@ -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++ ) {
Expand Down
4 changes: 3 additions & 1 deletion test/unit/traversing.js
@@ -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() {
Expand Down

5 comments on commit f1f6bc3

@jdalton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for the switch ?

@jeresig
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jupiterjs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@leeoniya
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thus leaving

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

EDIT: nvm...durrr

@jeresig
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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