In a web page there is a div with a value specified for its class.
Now, I have with me the node corresponding to the div, how do I obtain the class of that div, using the node (which is stored in a js variable)?
Example–
<div class="test" id="div1">
Some random text
</div>
How do I obtain the class value (i.e. “test”) when I have with me the node that represents the above div?
http://jsfiddle.net/XWqu8/
Prints in the Javascript console:
Note as well that a
classvalue can represent multiple classes, e.g.:http://jsfiddle.net/XWqu8/
Which prints: