Reputation: 4342
I am trying to get an elements class name. First I find the element by its id and then I tried to get the class attribute doing the following. My results return undefined. How can I get the text from the class attribute? Which would be "not-checked-in".
html
<div id="last-check-in" class="not-checked-in"></div>
javascript
var checkedin;
checkedin = document.getElementById("last-check-in");
console.log(checkedin.class);
Upvotes: 1
Views: 6459
Reputation: 9469
You may use: getAttribute("class")
var checkedin;
checkedin = document.getElementById("last-check-in");
console.log(checkedin.getAttribute("class"));
Upvotes: 1
Reputation: 219946
Instead of simply class
, use className
:
var checkedin = document.getElementById("last-check-in");
console.log(checkedin.className);
Upvotes: 3