This question completes the first one that I asked here about how to change an image on click using jQuery.
I forgot to say (even if I edited my post later) that I'm looking for a way to have a different alt attribute each time an image is changed by click.
(This is for better accessibility and SEO optimization.)
Here is the actual html code thanks to altCognito:
<img id="radio_btn1" src="originalimage1.jpg" />
<br />
<input type="radio" name="radio_btn1" value='image1.jpg' />
<input type="radio" name="radio_btn1" value='image2.gif' />
<input type="radio" name="radio_btn1" value='image3.png' />
<input type="radio" name="radio_btn1" value='image4.jpeg' />
And the jquery:
imgFldr = 'images/nameofthesubfolder/';
$("input[type='radio']").click(function() {
$('#'+this.name).attr('src', imgFldr+this.value).attr('alt', 'newattribute');
});
It can be edited at jsbin.