The JavaScript below only replaces the src for one image on a page how can i get it to do it for multiple images on the same page
<SCRIPT LANGUAGE="JavaScript">
loadImage1 = new Image();
loadImage1.src = "http://4.bp.blogspot.com/-Xzm-yUJ_dz0/Tsj3Q57J2tI/AAAAAAAAAGE/bohLMRj5FCY/s1600/hover.png";
staticImage1 = new Image();
staticImage1.src = "http://3.bp.blogspot.com/--0FurTdrYzg/Tsj3RPXGz4I/AAAAAAAAAGI/mm_4UvmoD-A/s1600/standard.png";
replaceImage1 = new Image();
replaceImage1.src = "http://4.bp.blogspot.com/-oacZCbBUhQ0/Tsj3Qkl4IaI/AAAAAAAAAGA/5_z-2VXKCi8/s1600/clicked.png";
</script>
The Image HTML is below if required.I don’t mind applying and ID or CLASS to the images either 🙂
<img onMouseOver="image1.src=loadImage1.src;" onMouseOut="image1.src=staticImage1.src;" onmousedown="image1.src=replaceImage1.src;" onmouseup="image1.src=loadImage1.src;" style=width:480px;height:360px;background-image:url('http://i1.ytimg.com/vi/XtNcZnfkL2A/hqdefault.jpg');" name="image1" src="http://3.bp.blogspot.com/--0FurTdrYzg/Tsj3RPXGz4I/AAAAAAAAAGI/mm_4UvmoD-A/s1600/standard.png">
AND/OR is there a cleaner jquery for this I would much rather use jQuery, thankyou!
You can do it as:
Add a class to images , like;
Then using jQuery you can select all the images having the same classname, like;
$("img[class='someClass']").each(function() { //replace src attribute of each image $(this).attr("src", ""); $(this).attr("src", "your_new_src"); });Hope it helps