Now i'm going to explain you about click events. An event can be generated by clicking of mouse or pointing of mouse. Its very simple just use objects and make their this function. Main benafit of javascript is that it can be embedded in HTML very easily either in head section or body section or you may create a seprate file of javascript and save that file with the extension of .js
The simple method of adding javascript file in html is to call that file in head section.
The simple method of adding javascript file in html is to call that file in head section.
HTML & Javascript Code :
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
<title>click event</title></head>
<body>
<div id="box" onmousedown="mDown(this)" onmouseup="mUp(this)"> Click me</div></br>
</br>
<div id="box" onmouseover="mOver(this)" onmouseout="mOut(this)"> click me too</div>
<script type="text/javascript">
function mDown(obj)
{
obj.style.backgroundColor="blue";
obj.innerHTML="release me"
}
function mUp(obj)
{
obj.style.backgroundColor="#F17A9E";
obj.innerHTML="Click me"
}
function mOver(obj)
{
obj.style.backgroundColor="green";
obj.innerHTML="mouse is on me"
}
function mOut(obj)
{
obj.style.backgroundColor="#F17A9E";
obj.innerHTML="mouse is not on me"
}
</script>
</body>
</html>
CSS:
#box{
background-color:#F17A9E;
padding:20px 10px 40px 20px;
height:30px;
width:60px;
margin-left:30px;
}
Enjoy this code and apply it as per your requirment. Hope you will like this.
Comments
Post a Comment
your Comment is sent for moderation, Thankyou