Created
July 31, 2014 00:16
-
-
Save massiws/e36da995d25205502451 to your computer and use it in GitHub Desktop.
JQUERY: Toggle DIVs with radio buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Toggle DIVs with radio buttons</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(function() { | |
$("[name=toggler]").click(function(){ | |
$('.hide').hide(); | |
$("#div-" + $(this).val()).show(); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<label>Show first DIV<input id="rdb1" type="radio" name="toggler" value="1" /></label><br/> | |
<label>Show second DIV<input id="rdb2" type="radio" name="toggler" value="2" /></label> | |
<fieldset style="width:200px;"> | |
<div id="div-1" class="hide" style="display:none"> | |
<p>I'm the first DIV!</p> | |
</div> | |
<div id="div-2" class="hide" style="display:none"> | |
<p>I'm the second DIV!</p> | |
</div> | |
</fieldset> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment