javascript - Determine what CSS selectors are been applied to an element -


is there way determine if selector been applied given element?

i know it´s possible iterate on css selectors, , test if each 1 applicably or not. i´m not sure if way firebug , other inspector it.

edit: need way dynamically, js.

you can check if element instance matched selector using document.queryselectorall , array.prototype.indexof:

function elementmatchesselector(element, selector) {     return array.prototype.indexof.call(document.queryselectorall(selector), element) > -1; } 

of course works modern browsers support aforementioned methods.


alternatively can use element.matches:

function elementmatchesselector(element, selector) {     var fn;     if (!element) {         return false;     }     fn = element.matches || element.mozmatchesselector || element.msmatchesselector || element.webkitmatchesselector;     if (fn) {         return fn.call(element, selector);     }     return false; } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -