Why class attribute cannot assign inline by javascript?
use className
, so change:
var div = document.getElementsByTagName("div");
div[0].class = "tagging";
to
var div = document.getElementsByTagName("div");
div[0].className = "tagging";
Demo:: jsFiddle
You need to use className
.
Try:
div[0].className = "tagging";
If you want to add tha class to the existing one you can use:
div[0].className += " tagging"; // adding white-space is important
Demo here
To read: MDN className.