Change element style by style name and value in Javascript

Description

The following code shows how to change element style by style name and value in Javascript.

Example


<html>
<body>
  <div id="div1" style="background-color: red; height: 50px; width: 50px"
    onmouseover="this.style.setProperty('background-color', 'blue', '')"
    onmouseout="this.style.setProperty('background-color', 'red', '')"></div>
</body><!--from  w w  w .  java 2s . c o m-->
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window