Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#8384 closed bug (wontfix)

Request for ">" selector to work in wider range of circumstances

Reported by: [email protected] Owned by:
Priority: low Milestone: 1.next
Component: selector Version: 1.5.1
Keywords: neededdocs Cc: john, jeresig
Blocked by: Blocking:

Description

According to the specification > is only defined where parent and child are specified, 'parent > child', which arguably makes sense when used as an initial selector to set up a new jQuery object (although you coud also argue that "> child" could refer to children of body).

But where a context is specified e.g (">p", context), the selector is still valid (even though this isn't documented).

However, in other "contexty" contexts, using > without a parent does not work

e.g.

  • $(el).closest(">li", context)
  • $(context).delegate(">li", ...)

This

  • a) makes for an inconsistent and confusing api
  • b) limits/complicates the use of some otherwise straightforward and very useful jQuery methods

So I reckon jQuery should try and make > more widely applicable and, as a stopgap, at least update the documentation to clarify where > can and cannot be used

test page - http://jsfiddle.net/DMVDS/1/

Change History (5)

comment:1 Changed 12 years ago by john

Component: unfiledselector
Keywords: needsdocs added
Priority: undecidedlow
Status: newopen
Type: enhancementbug

So yeah, we're not looking at add in new selectors that are invalid CSS selectors - and actually we're looking to deprecate $(">p", context). We'll look to document this.

comment:2 in reply to:  1 Changed 12 years ago by wheresrhys

Replying to john:

So yeah, we're not looking at add in new selectors that are invalid CSS selectors - and actually we're looking to deprecate $(">p", context). We'll look to document this.

On the other hand there's a selector to match most (?all) of jQuery's DOM traversal methods, and not allowing ">p" means there is no equivalent for .children("p"), which isn't so much an argument for keeping the selector, but it does provide some rationale for not deprecating what is (or would be if it always worked) a very useful selector

e.g in an accordion plugin you could use $(".myAccordion").delegate(">li", "click" , toggle) Without it the plugin would have to add a class to each child li to allow for the possibility of nested lists. (I just noticed it's used as a selector in jquery.ui http://jqueryui.com/demos/accordion/)

And while the parent isn't explicitly defined in the selector, it is very strongly implied when you consider the DOM nodes in the jQuery object to be the parents, so while not strictly speaking valid CSS, it's far from being CSS nonsense

Last edited 12 years ago by wheresrhys (previous) (diff)

comment:3 Changed 12 years ago by addyosmani

Cc: john jeresig added

@john: With respect to your comments above, is the plan to deprecate $(">p", context) in 1.7 or one of the other upcoming future releases?

I ask as because we haven't yet defined a set action to along with this ticket it's hard to know whether any docs can be structured around this.

Would 'Note: $(">elem", context) may be deprecated in a future release and we discourage it's usage in lieu of alternative selectors at this time', suffice for now?

comment:4 in reply to:  3 Changed 12 years ago by john

Resolution: wontfix
Status: openclosed

Replying to addyosmani: Yep, that sounds fine to me!

comment:5 Changed 12 years ago by addyosmani

Keywords: neededdocs added; needsdocs removed
Note: See TracTickets for help on using tickets.