<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div>
<div>
<label id="radio" for="select_radio">Select x</label>
</div>
<div>
<div>
<input name="select_radio" value="Yes" id="radio_yes" type="radio" checked>
<label id="label_radio_yes" for="yes">Yes </label>
</div>
<div>
<input name="select_radio" value="No" id="radio_no" type="radio">
<label id="label_radio_no" for="no">No </label>
</div>
</div>
</div>
<div class="sub-element">
<div class="grandparent">
<p>I am the grandparent 1</p>
<div class="parent">
<p>I am the parent</p>
<div class="child">
<p>I am the child</p>
<input class="child" value="Y" id="checkbox_0" type="checkbox">
<label id="label_2" for="checkbox_2" class="child">Add another</label>
</div>
</div>
</div>
<div class="grandparent">
<p>I am the grandparent 2</p>
<div class="parent">
<p>I am the parent</p>
<div class="child">
<p>I am the child</p>
<input class="child" value="Y" id="checkbox_1" type="checkbox">
<label id="label_3" for="checkbox_3" class="child">Add another </label>
</div>
</div>
</div>
<div class="grandparent">
<p>I am the grandparent 3</p>
<div class="parent">
<p>I am the parent</p>
<div class="child">
<p>I am the child</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.0.3.js"></script>
</div>
</body>
</html>
var grandParents = $(".grandparent");
var subContainer = $(".sub-element");
var checkbox_0 = $("#checkbox_0");
var checkbox_1 = $("#checkbox_1");
var state = {
open: false,
checkbox_0: false,
checkbox_1: false
};
//hide everything on load at first except for first element
grandParents.each( function(index, el){
if(index === !0){
$(this).hide();
}
});
//check the radio value on pageload
checkRadioOnLoad();
//check inputs on pageload
checkInputs();
$(":radio[name='select_radio']").on('change', function() {
var masterSelect = $(this).val();
if(masterSelect === "Yes"){
state.open = true;
}else{
state.open = false;
}
toggleContainer();
});
$(checkbox_0).on('change', function() {
if(this.checked){
state.checkbox_0 = true;
}else{
state.checkbox_0 = false;
}
//re-run check
checkInputs();
});
$(checkbox_1).on('change', function() {
if(this.checked){
state.checkbox_1 = true;
}else{
state.checkbox_1 = false;
}
//re-run check
checkInputs();
});
function toggleContainer(){
if(state.open === true){
subContainer.show();
}else{
subContainer.hide();
}
}
function checkInputs(){
if(state.checkbox_0){
checkbox_1.parent().parent().parent().show();
}else{
checkbox_1.parent().parent().parent().hide();
}
if(state.checkbox_1){
$(grandParents[2]).show();
}else{
$(grandParents[2]).hide();
}
}
function checkRadioOnLoad(){
if($("#radio_yes")){
state.open = true;
}else{
state.open = false;
}
}
Output
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |