I use this code in order to show/hide select box depends if a checkbox is checked or not:
jQuery(document).ready(function($){
$('[type="checkbox"][name="fields[special_proj_checkbox_field][]"]').change(function(){
$('select.select').toggle(this.checked);
});
});
This code is executed in the back-end, in the edit post screen.
It works well except for one thing — the first time I get to the edit post screen, the checkbox isn’t checked, but the select box is visible, only after I check the checkbox and unchecked it again, the box is hiding.
How can I make it hidden by default?
You can initially hide the select
As far as I know jQuerys
.hide()
function is triggeringdisplay:none
. So you may initially adddisplay:none
to your box or add a$.hide()
at the very beginning of your code.