Qualified Selectors in MooTools

My friend Mike Horn asked me to come up with a solution for a pseudo selector in MooTools that John Resig wrote about for jQuery. To sum it up, the pseudo selector basically grabs the element that \”has\” or contains the passed-in element. After taking a look at that I came up with something.

The Code

//Add the pseudo selector
Selectors.Pseudo.has = function(arg){
    return (this.getElement(arg)) ? this : false;
}

//Returns anchors that has img elements
$$(\'a:has(img)\');

But, correct me if I\’m wrong, we can\’t do the following and expect the same thing:

// returns an array of img elements, instead of anchors
$$(\'a < img\');

What do you guys think? Is this the way to go for the pseudo \"has\" selector?

One thought on “Qualified Selectors in MooTools”

Leave a Reply

Your email address will not be published. Required fields are marked *