Here is what I want to do. There are four icons, and when we click on an icon, its background image should change. When we click again on it, the first image should come again. Here is my code. Thanks for your help ; I spent some time but I didn't find the solution: the "if" block doesn't not recognize the value of the background. Thanks a lot for helping me.
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Test</title>
<style type="text/css">
#image1, #image2, #image3, #image4 {
background: url('icon1.png');
width:24px;
height:24px;
}
</style>
</head>
<body>
<p id="image1" onclick="change(this)"></p>
<p id="image2" onclick="change(this)"></p>
<p id="image3" onclick="change(this)"></p>
<p id="image4" onclick="change(this)"></p>
<script type="text/javascript">
function change(element) {
if(element.style.background == "url('icon1.png')") {
element.style.background = "url('icon2.png')";
} else {
element.style.background = "url('icon1.png')";
}
}
</script>
</body>
</html>