I would like to create an event listener to update an image somewhere on the page (but out of the form tags) depending of a radio button choice. I know it is possible with JQuery but I am a noob on Javascript. Does someone could help me please?More specifically the user wanted to add a class to an image when a radio button option was selected and added: If value A is selected > myClass = classA, if it's value B > myClass = classB The solution is below.
<script type="text/javascript">
jQuery(document).ready(function($) {
$('input[name="item_meta[2127]"]:radio').click(function(){
switch($(this).val()) {
case "Option 1":
$("#your-image-ID").addClass("classA");
$("#your-image-ID").removeClass("classB");
break;
case "Option 2":
$("#your-image-ID").addClass("classB");
$("#your-image-ID").removeClass("classA");
break;
}
});
});
</script>
Please login or Register to submit your answer