JG Vimalan's Blog

Sharing is caring :)

Setting css class with javascript

In this post, I am going to explain about setting css class for controls using javascript.

The following javascript will give you an idea of setting css class to a control for IE and other browsers.

//Javascript

var anchl = document.getElementById(‘largeFontSwitch’); //Id of the control

//Remove class
anchl.setAttribute(“class”, “”); //Other browsers
anchl.className = “”; //IE

//Set class

anchl.setAttribute(“class”, “selectedFont”); //Other browsers
anchl.className = “selectedFont”; //IE

September 6, 2011 Posted by | JavaScript | Leave a comment