Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript The future of jQuery custom selectors without Sizzle

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #288631
    Shikkediel
    Participant

    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…

    #288632
    Shikkediel
    Participant

    The 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…

    #288928
    Shikkediel
    Participant

    Follow 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 (or document 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.

    #288929
    Shikkediel
    Participant

    Live example:

    codepen.io/wbZVrJ

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.