Style property
style is a property of element object or node object in javascript.
Example
document.getElementById("id_name").style.color = "red";
|
<html>
<head>
<title>getElementsByName example</title>
<script type="text/javascript">
function applyCSSStyle(className,cssname,cssvalue){
var elements = document.getElementsByClassName(className);
for (var index in elements){
if (!isNaN(index))
elements[index].style[cssname] = cssvalue;
}
}
window.onload = function(){
applyCSSStyle("go_green","color","green");
applyCSSStyle("go_background_red","backgroundColor","red");
};
</script>
</head>
<body>
<div class="go_green">
Green Color
</div>
<div class="go_green go_background_red">
Red background Color with green text
</div>
</body>
</html>
|
Demo & Output
|