Move this topic
Closest work with open child selector
Implemented
- Implemented
- Will not implement
- In-progress
- Under review
- Maybe later
in Developing jQuery Core
•
2 years ago
I'm not sure delegating from non-document elements is not officially supported. But, I'd like to be able to do something like the following:
$(">ul>li>a", el).live("click", func)
because: $(el).find(">ul>li>a") works.
for this to work, filter would need a context, but this starts going into Sizzle. Is this something sizzle could support?
3
Replies(6)
Re: Closest work with open child selector
2 years ago
So I don't think that this is a direction that we can move in. We're going to try and match the functionality of the matchesSelector() method now in browsers and that does not take an extra argument. When talking with the browser vendors we agreed that those "malformed" selectors aren't really something that we want to support - so yeah, I suspect we'll just have to punt on it.
Leave a comment on jeresig's reply
Re: Closest work with open child selector
2 years ago
Ok, is there an alternative? Will this still work with .find?
I wonder what's a good way of do with this when you have a nested structure and you only want the first level.
Ah, I just realized something a little troublesome. If jQuery is going to follow matchesSelector, then plugins that use event delegation might match unexpected events. Say you had a selector like:
".foo .bar" in your plugin. Within your plugin's main element, there is a ".bar" element, but it is not in a ".foo" element. If the use,r by mistake, wrapped your entire widget with ".bar", they would start triggering these events.
I can't seem to find the spec. Is it browser-only at this point? It probably should include a 2nd argument, enabling limited, contextual matching.
It's as important as having querySelectorAll work from elements (and element lists) other than the document. Its a parallel need.
Re: Closest work with open child selector
2 years ago
To clarify, querySelectorAll ALSO does not support rooted selectors like "> div". We're only supporting it at this point due to legacy. As far as I know it's browser-only at this point.
Leave a comment on Guest's reply
Re: Closest work with open child selector
2 years ago
John,
Yeah, I understand your clarification. But, I am back today to complain about this again b/c I can't make a reasonable event based architecture work without this feature (or without hacking it in). The core problem is that you want to let all events propagate up so someone else can respond to them. However, with nested widgets (like a Tree), you can't be sure if the event happens on a sub-widget or the current widget.
The following is how a Tree widget with ajax might work. Assume that the tree is comprised of 'ul' and 'li's. I want something like:
- $('.tree').live("open", function(ev){
- $.get("/somewhere", {}, function(text){
- $(ev.target).closest('li').append(text )
- }
- })
But I want to also use open for showing and hiding sub 'ul's. But to do this I need something like:
- $(current_widget_element).delegate(">li","open", function(){
- $(this).show()
- })
I understand that this doesn't match the spec, but I think this is going to be something people crave as delegate gets more common and people start running into this.
If you aren't willing to bring this into jQuery, what would be the best way of hacking it in? The problem would be selectors like:
">.foo a"
I'm not sure how to get sizzle's filtering to return the".foo" element.
Thanks for your help.
Leave a comment on justinbmeyer's reply
Re: Closest work with open child selector
2 years ago
Hey Justin,
I'm afraid I must be missing something, but regarding your last question about returning the .foo element, couldn't you just do '>.foo:has(a)' ?
--Karl
I'm afraid I must be missing something, but regarding your last question about returning the .foo element, couldn't you just do '>.foo:has(a)' ?
--Karl
Leave a comment on kswedberg's reply
Re: Closest work with open child selector
2 years ago
Great suggestion! It isn't a perfect solution, but I can probably hack in '>' support as long as there are no spaces after it, unless they are inside a :has.
I'll just check that .currentTarget.parentNode == the delegating node.
Thanks for the idea.
--how extremely stupid not to have thought of that ... T.H. Huxley
Leave a comment on justinbmeyer's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic
Reply to justinbmeyer's idea
Statistics
- 6 Replies
- 2124 Views
- 2 Followers



