New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposing filter pseudo functions for use with elements directly #3046
Comments
The pseudo selectors are in |
@dmethvin Ah ok. I didn't realize they were accessible. Sorry for not catching that. And sure. It's not that it's a performance bottlenecks per se. It just feels silly to rewrite the same code if already available. And in a vanilla js context, having to use the wrapper outside of jQuery's scope is unnecessary, and at least, feels out of context. So it is safe to write a plugin/helper function using the $.expr.filters object? |
For your own use? Probably so, but I'll let some others think about it. As a public plugin you'd need to think about things like whether people are using the alternate selector engine or whether some of the pseudos might be deprecated in the future. |
Yeah, for my own use. Given the extensible API. It's manageable, even if removed.
Which gives: Also, there are 3 filter objects, which are essentially the same: Any one best to use, for future-proof compatibility? |
Slightly as an aside to this, but on the same topic:
|
Getting a DOM element into a jQuery object is one of the fastest paths in the code, just a couple of Since |
Agreed, I don't see us adding this to the API. However, this might be a good candidate for a plugin. |
Very often I am wanting to get access to common pseudo methods such as:
:focus
,:selected
,:checked
or:empty
etc. for a single target element in an event callback.For that, I currently have two options:
$.fn.is(:peudo)
selector.Both are however wasteful of resources. Given that those methods (taking a single element argument), are already in the code base. They have a legit case to be used directly. But they are not exposed...
Could they be exposed to an
$.is
set of functions as well. It would allow simple efficient checks like$.is.focus(el)
without having to go through creating a new object and runs regex exprs needlessly?The text was updated successfully, but these errors were encountered: