Switch Image in Javascript
Program:
<html>
<head>
</head>
<body>
<img id='myimage' border="0" src="emoticon-25530_640.png" alt="Smiley" width="140" height="140">
<script>
var img=document.getElementById('myimage');
img.onmouseover=swapImage;
img.onmouseout=normalImg;
var check = true;
function swapImage() {
if (check==true){
this.setAttribute('src','smiley-25521_640.png');
check=false;
}
else {
this.setAttribute('src','emoticon-25530_640.png');
check=true;
}
this.style.height = "196px";
this.style.width = "196px";
}
function normalImg() {
this.style.height = "140px";
this.style.width = "140px";
}
</script>
</body>
</html>
Output:
No comments:
Post a Comment