How to make this tag <h3>
appear when a checkbox is clicked? Right now it is hidden.
<h3 class="bark">Bark Bark</h3>
<input type="checkbox" class="title">Hear a dog</input>
css:
.bark{
visibility: hidden
}
input[type="checkbox"]:checked {
visibility: visible
}
The <input type="checkbox"> defines a checkbox. The checkbox is shown as a square box that is ticked (checked) when activated. Checkboxes are used to let a user select one or more options of a limited number of choices. Tip: Always add the <label> tag for best accessibility practices!
To show or hide the field, we are applying CSS through jQuery css() method. We are passing CSS display property. To hide the field, we set the display property to none and to show it we set the display property block. So you have seen how to show or hide input field depending upon a checkbox field.
.bark{
visibility: hidden
}
input[type="checkbox"]:checked + h3.bark {
visibility: visible
}
<input type="checkbox" class="title">Hear a dog</input>
<h3 class="bark">Bark Bark</h3>
Without using scripting language there is one trick:
.bark{
visibility: hidden;
}
input[type="checkbox"]:checked + .bark {
visibility: visible;
}
<input type="checkbox" class="title">Hear a dog</input>
<h3 class="bark">Bark Bark</h3>
You should put h3
after input
. And use +
sign to make h3 visible.
Working Fiddle
function checkInput(cbox) {
if (cbox.checked) {
document.getElementById('check_box').style.visibility='visible';
}
else{
document.getElementById('check_box').style.visibility='hidden';
}
}
#check_box{
visibility: hidden;
}
<h3 id="check_box">Bark Bark</h3>
<input type="checkbox" class="title" onclick="checkInput(this);">Hear a dog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With