Add class name to div id
Here is a script to add an extra class name to a div with an id regardless of what is there now.
function addClassName (id, classname) { var e; if (typeof(id) == 'string') {e = this.getElementById(id);} else {e = id;} if (!e || typeof e.className != 'string') { throw "Cannot add class to element " + id; } /* Check if the class is already there */ if (!e.className.match(new RegExp('\\b' + classname + '\\b'))) { e.className += ' ' + classname; } }
Labels: All, Javascript