Trying to explain my idea with an example since it's a bit tricky. Imagine we have this HTML code:
<ul>
<li id="myli" class="myclass">Hello</li>
</ul>
along with the corresponding CSS:
.myclass{
color:red;
}
li.myclass{
background-color:black;
}
ul li{
float:left;
}
Now, the goal is to develop a JavaScript function that takes a DomElement as input and retrieves all the matching selectors from the CSS files for that element (similar to the F12 toolbar in Chrome that displays all styles for an element), like this:
var mySelectors = GetSelectorsForElement(document.getElementById("myli"));
and the result stored in mySelectors would be:
[".myclass",
"li.myclass",
"ul li"]
Is it possible to accomplish this in JS?