But if you're not allowed to use any such libraries, then you would have to rely on the browser's built-in method **getAttribute **to achieve the functionality.
The below code would alert the class value of *'myElem'Â *in all browser's. But, Internet Explorer would just say 'null'Â!
var elem = document.getElementById("myElem"); alert(elem.getAttribute("class"));
To make that work in Internet Explorer, change to 'className'Â and see what happens!
var elem = document.getElementById("myElem"); alert(elem.getAttribute("className"));
Now the above code will work *only in Internet Explorer *but will fail in all other browsers.
So what's the correct solution that works in *all browser? *Well, don't use the getAttribute() *method at all. Instead, use the property *className **to get the class attribute value.
Here's the cross-browser solution:
var elem = document.getElementById("myElem"); alert(elem.className);
That should do the trick!