I have three radio buttons and a div after each one like this:
<input type="radio" name="radios" id="my_radio_1" value="" />
<div id="my_radio_1_text" style="display:none;">Content for radio 1</div>
<input type="radio" name="radios" id="my_radio_2" value="" />
<div id="my_radio_2_text" style="display:none;">Content for radio 2</div>
<input type="radio" name="radios" id="my_radio_3" value="" />
<div id="my_radio_3_text" style="display:none;">Content for radio 3</div>
As you can see, the divs are initially hidden with display:none;
. What I'm trying to do is to show the div right after each radio button when it is selected (and if a radio button is not selected, I want to hide the div after it). I can show the div after a radio button when it is selected by doing this:
$(document).on('change', 'input:radio[name=radios]', function(){
$('#' + $(this).attr('id') + '_text').show();
});
But I don't know how to hide the div when another radio button is selected. Any ideas please?