I have a HTML Element, or list item, which has both an id
and a class
assigned to it. I am writing automated tests, and I need to check the class
for this element. In the test, when I call window.document.getElementById('my-element-id')
, it does return the correct element, but there is no class
property on it. Is there another way to check the class
?
The property you're looking for is className
.
Here's a working example: http://jsfiddle.net/xxEtj/
HTML
<ul>
<li id="myId" class="myClass">Item one</li>
</ul>
JS
var li = document.getElementById('myId');
alert(li.className);
document.getElementById('my-element-id').className
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With