I know that Attr gets the exact class of an element. Is there a way to get the element exact class as defined in CSS?
For example an element may have class "title" but be defined in CSS as a descendant selector, something like: .other-list .title {}
I need something to get that exact class value. You can see here the full example:
http://jsfiddle.net/2TMgQ/2/

On click both elements have class "title" but are defined in CSS as 2 different elements.
Thank you

YEap, I need to. Indeed Firebug does it. I do not think that i will be able to understand the FireBug code. That was the first place i had looked in to, I thought that there is an easier way... how about this: developer.mozilla.org/en/DOM/cssRule.selectorText
–
MirceaJul 6 '10 at 21:06

Indeed they are using "selectorText", just looked again to their code. Can't figure it out how, the code is to big to understand it
–
MirceaJul 6 '10 at 21:12

2

@Mircea - Let me put it this way...the Firebug guys are good, and they wouldn't do it a way that's more complicated that was required (for them). You can strip from their implementation because you don't need all that functionality, but just finding the rules isn't easy. For example what if 10 rules applied to your element, then what? Which do you use? It could always be a list, what if your example was this instead? jsfiddle.net/2TMgQ/9
–
Nick Craver♦Jul 6 '10 at 21:18

1

@Marko - Why were the plates in the glasses? Was it really big glasses or really little plates?
–
Nick Craver♦Jul 6 '10 at 21:42

3 Answers
3

This should get you all CSS styles that apply to the element. It uses jQuery's is function to check if a CSS rule selector applies to a given element. Iterate through all stylesheets in document.styleSheets, and through all cssRules in each stylesheet, and check if selectorText matches the element. In pseudocode: