mardi 12 janvier 2016

Show select box only when checkbox is checked

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?




Aucun commentaire:

Enregistrer un commentaire