Dynamically changing attributes

var div = document.getElementById('div1'); // Clear Value div.setAttribute('style',''); // OR div.removeAttribute('style'); // Set Style / Append Style div.style.backgroundColor = '#ff0000'; function getStyleSheet(unique_title) { for(var i=0; i<document.styleSheets.length; i++) { var sheet = document.styleSheets[i]; if(sheet.title == unique_title) { return sheet; } } }

Adding and Removing Rules

stylesheet.insertRule(".have-border { border: 1px solid black;}", 0);

Changing Element Styles

function colorElementRed(id) { var el = document.getElementById(id); el.style.color = "red"; }

 

function changeElement(id) { var el = document.getElementById(id); el.style.color = "red"; el.style.fontSize = "15px"; el.style.backgroundColor = "#FFFFFF"; }