Bird of the Sea introduces the javascript onclick event

  • 2020-11-25 07:06:42
  • OfStack

Definition and usage of onclick events:

This event is triggered when an object is clicked.

Browser support:

1.IE browser supports this event.
Firefox supports this event.
3.Opera browser supports this event.
4. Google browser supports this event.
5.safria browser supports this event.

Example code:


<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="author" content="https://www.ofstack.com/" />
<title> The home of the script </title>
<style type="text/css">
div{
width:100px;
height:100px;
background-color:red;
}
</style>
<script type="text/javascript">
window.onload=function(){
var mydiv=document.getElementById("mydiv");
mydiv.onclick=function(){
mydiv.style.backgroundColor="green";
}
}
</script>
</head>
<body>
<div id="mydiv"></div>
</body>
</html>

Through the above content to give you a brief introduction to javascript onclick event, I hope to help you.


Related articles: