Qualified Selectors in MooTools
Posted on | December 24, 2008 | 1 Comment
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
1 2 3 4 5 6 7 | //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:
1 2 | // 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?
Comments
One Response to “Qualified Selectors in MooTools”
Leave a Reply
March 9th, 2010 @ 2:30 am
‘a < img' must equal this Pseudo Selector:
Selectors.Pseudo.has = function(arg){
return (this.getChildren(arg)) ? this : false;
}