What is the simpliest method to change image src, when I click on a href -with JQuery?
img id="my_image" class="icon" src="1.png" alt="1.png" border="0" />
1.png, 2.png, 3.png
< a href="#" id="1">
< a href="#" id="2">
< a href="#" id="3">
Href is OK with # or would be better to placce here some JS?
You should .bind()
help a .click()
help event listener on your anchors. In that listener, you change the src attribute by invoking .attr()
help
$('a').click(function(event) {
$('#my_image').attr('src', function(i, src) {
return event.target.id + '.png';
});
return false;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With