How do I toggle two images using jQuery and radio buttons?
Posted
by trench
on Stack Overflow
See other posts from Stack Overflow
or by trench
Published on 2010-06-08T04:25:40Z
Indexed on
2010/06/08
4:32 UTC
Read the original article
Hit count: 178
This isn't pretty, but I think you'll get what I'm trying to do.
<label><input name="jpgSel" type="radio" value="0">jpg 1</label><br />
<label><input name="jpgSel" type="radio" value="1">jpg 2</label><br />
<div id="showjpg"></div>
and
$(document).ready(function() {
$("select").change(function () {
if ($("jpgSel:checked").val() == 1) {
$('#showjpg').attr({
src: 'one.jpg',
alt: 'one dot jpg'
});
}
else {
$('#showjpg').attr({
src: 'two.jpg',
alt: 'two dot jpg'
});
}
});
© Stack Overflow or respective owner