I need to switch my element background image beetwin two images on every click on it.
I have this, byt it swithes color just two times =\
<html>
<head>
<title>Javascript Change Div Background Image</title>
<style type="text/css">
#div1 {
width:100px;
height:30px;
background-image:url(blue.png);
}
</style>
<script language="javascript" type="text/javascript">
function changeDivImage() {
var imgPath = new String();
imgPath = document.getElementById("div1").style.backgroundImage;
if (imgPath == "url(blue.png)" || imgPath == "") {
document.getElementById("div1").style.backgroundImage = "url(green.png)";
}
else {
document.getElementById("div1").style.backgroundImage = "url(blue.png)";
}
}
</script>
</head>
<body>
<center>
<p>
This Javascript Example will change the background image of<br />
HTML Div Tag onclick event.
</p>
<div id="div1">
</div>
<br />
<input type="button" value="Change Background Image" onclick="changeDivImage()" />
</center>
</body>
</html>