Home › Forums › JavaScript › The future of jQuery custom selectors without Sizzle
- This topic is empty.
-
AuthorPosts
-
May 30, 2019 at 6:24 am #288631ShikkedielParticipant
Needing a way to select all elements to which I apply a data object, I came across
jQuery.expr.pseudos
. Late to the game to notice its existence (very little documentation about it) but it looks very promising.An idea of what it does can be found here.
In short, a pseudo selector could be added to the element and then selected by
$(':mypseudo')
. This is something neat that the Sizzle engine can do.But in the latest jQuery release documentation it says that the end of using Sizzle is in sight and that positional selectors will be removed…
My question – will jQuery still support the same syntax with version 4.0? Or would trying to apply this to my own plugin mostly be a waste of effort…
May 30, 2019 at 6:28 am #288632ShikkedielParticipantThe removal of positional selectors such as
:first
and:eq
will have major consequences for existing scripts by the way.Edit:
Doing a
console.log($.expr.pseudos)
and seeing all the selectors that will have to be maintained, I can’t see how they will be completely removing it. I’m taking a bet on it still being available in future releases.Most times I come up with something after hours of reading and posting a question here…
June 5, 2019 at 7:44 am #288928ShikkedielParticipantFollow up question… I’ve been messing with this for hours. Hope someone’s out there with some insight, topics on this are pretty rare.
How can I include
window
here? It traversed all main elements but doesn’t include that (ordocument
but that’s not an issue).$.expr.pseudos.mypseudo = $.expr.createPseudo(function() { return function(snip) { return $(snip).data('mypseudo'); } });
The above returns all elements that have a
mypseudo
data object attached.Seems simple enough at first glance but I’m clearly not fully grasping what is happening there. All attempts are futile so far.
June 5, 2019 at 8:03 am #288929ShikkedielParticipantLive example:
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.