I need some simple JQuery code so I can change the src value of a specific img.
It\'s currently:
<
$("#myImage").attr('src', 'image2.gif')
You could use the .attr() function to set attributes on given DOM element:
$(function() {
$('#myImage').attr('src', 'image2.gif');
});
$('#myImage').attr('src','theothersrc.gif')
Using: $(function(){ ... });
You can use:
$('#id').attr('src', 'newImage.jpg');
to change the image source immediately.
Alternatively, you can use jQuery animations to change an image.
JS
$("#id1").fadeOut();
$("#id2").delay(200).fadeIn();
HTML
<div>
<img id='id1' src='one.jpg'>
<img id='id2' src='two.jpg'>
</div>
(Don't forget to change the CSS of #id2
and put display: none
as initial state).
That's elementary, use jQuery attr...
$('img#myImage').attr('src', 'image2.gif');