Handle onclick event on input element

Description

The following code shows how to handle onclick event on input element.

Example


<html>
<head>
<script type="text/javascript">
  function getColor() {<!--from  w  w  w  .  j a v  a2 s.com-->
    var oDiv = document.getElementById("myDiv");
    alert(oDiv.style.color);
  }
</script>
</head>
<body>
  <div id="myDiv"
    style="background-color: red; height: 50px; width: 50px; color: yellow"></div>
  <br />
  <input type="button" value="Get Background Color" onclick="getColor()" />
</body>
</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