Get DIV class value using JavaScript

The question is simple. Not using jQuery ... how to get the value classin a DIV using regular JavaScript?

Thank.

+3
source share
2 answers

Assuming this HTML

<div id="Target" class="MyClass" />

Like this

var ElementCssClass = document.getElementById("Target").className;
+8
source

get a link to a div and use .className

document.getElementById('someDiv').className
+9
source

All Articles