This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
There has been some suggestions to introduce a new Element.matchesSelector() method. http://lists.w3.org/Archives/Public/public-webapi/2007Jan/0183.html http://lists.w3.org/Archives/Public/public-webapi/2008Apr/0128.html http://lists.w3.org/Archives/Public/www-style/2008Jul/0291.html Need to investigate use cases. Could possibly work something like this: foo.matchesSelector("section>p"); foo.matchesSelector("h1+:context"); Returns boolean.
More discussion of this proposal: http://lists.w3.org/Archives/Public/public-webapps/2008OctDec/0433.html http://lists.w3.org/Archives/Public/public-webapps/2008OctDec/0435.html http://lists.w3.org/Archives/Public/public-webapps/2008OctDec/0439.html http://lists.w3.org/Archives/Public/public-webapps/2008OctDec/0442.html http://lists.w3.org/Archives/Public/public-webapps/2008OctDec/0447.html
JQuery implementation http://docs.jquery.com/Traversing/is#expr
Mozilla have begun work on an implementation https://bugzilla.mozilla.org/show_bug.cgi?id=518003
Test Suite can be found here: http://github.com/jeresig/selectortest/tree/matchesSelector
Use Case: Event Delegation Listening to events on occurring on many elements is made easier by event bubbling, and listening for the event on a common ancestor element of those you want to listen for. This is commonly done on the body element. The technique relies on the ability to check which element or type of element the event target is. Having a function to check if the event target matches a particular selector makes this easier than having to manually check several different properties of the element. For example, executing some function of the event handler may depend on the element being an input element that is a checkbox and has is checked (i.e. matches the selector "input[type=checkbox]:checked". Checking each of these propertie separately in order to determine how to handle the event is more complicated.
WebKit implementation. https://bugs.webkit.org/show_bug.cgi?id=29703
matchesSelector() is now defined.