jQuery to show/hide divs using radio button
Use the jQuery to show/hide the divs using the radio button
Start with Radio button
Add two radio button with name myRadio value should be the different like
1. myDiv_1
2. myDiv_2
You can also use the
Show to Radio 1
Hide to Radio2
<input id="Div_1" name="myRadio" type="radio" value="myDiv_1" /> Radio 1 <input id="Div_2" name="myRadio" type="radio" value="myDiv_2" /> Radio 2
Now design the two new div to execute the command
First div id is myDiv_1 and you can also add the some style to define the div style, add the second div with id myDiv_2 with some style.
<div id="myDiv_1" style="width: 500px; background: white; color: black; border: 1px solid; padding: 5px;"> Content of Div 1 ... .. . </div> <div id="myDiv_2" style="width: 790px; background: white; color: black; border: 1px solid; padding: 5px;"> Content of Div 2 ... .. .</div>
Now you need to add the jQuery code to run the function properly
<script LANGUAGE="JavaScript">
$(document).ready(function(){
$("input[name$='myRadio']").click(function() {
var try = $(this).val();
$("div.MyDiv").hide();
$("#"+try).show();
}
});
</script>
It’s very easy to do this with jQuery, try it now and add your comments.
