skcin7
02-26-2011, 08:47 AM
Hello all. I am trying to make a function in jQuery that will change the SOURCE of an image. This is what I have so far but it does not work :( . How can this code be altered to change the source of an image???
function changeImage(imageName,imageSrc){
//This works, but I want to try it in jQuery style function
//document.getElementById(imageName).src = imageSrc;
//This does not work, there is something wrong with imageName
$("#imageName").attr("src", imageSrc);
}
The way I currently have my images is like this:
<a href="#" onmouseover="changeImage('home','./images/home_over.png');" onmouseout="changeImage('home','./images/home_under.png');">
<img id="home" name="home" src="./images/home_under.png" alt="HOME & UPDATES" />
</a>
function changeImage(imageName,imageSrc){
//This works, but I want to try it in jQuery style function
//document.getElementById(imageName).src = imageSrc;
//This does not work, there is something wrong with imageName
$("#imageName").attr("src", imageSrc);
}
The way I currently have my images is like this:
<a href="#" onmouseover="changeImage('home','./images/home_over.png');" onmouseout="changeImage('home','./images/home_under.png');">
<img id="home" name="home" src="./images/home_under.png" alt="HOME & UPDATES" />
</a>