My code below works in Firefox to toggle a border on an image,but does not work in IE. Any ideas why ? In IE, the first click will add the border, but the second click will not remove the border again.
Thanks,
Leslie
<html>
<head>
<script type="text/javascript">
window.onload=function(){
for(var i = 0; i < document.images.length; i++){
document.images[i].onclick=function(){
if(this.style.border == '2px solid red')
{
this.style.border='';
}
else this.style.border='2px solid red';
}
}
}
</script>
</head>
<body>
<div>
<img src="Cat.jpg" width="250"/>
<img src="Dog.jpg" width="250"/>
<img src="Fish.jpg" width="250"/>
</div>
</body>
</html>
You’ve used
if(this.style.border == '2px solid red'), and it’s rigth for FF butIE returns
red 2px solidso if condition doesn’t match with IE. You may try thisDEMO.
Alternative: DEMO or DEMO (Better when you’ve other classes).