I was recently working on a project, something jQuery-related for WP-Admin area.
I enable post-formats and create metaboxes for these post-formats, so at the end I tried to hide these metaboxes until the user checks the radio button. I just want to know if there is a better way I can write this code.
// hide the metabox at start
$('#gallery-box').hide();
// fetch the id name of checked post-format
var idName = $('input.post-format:checked').attr('id');
// display the metabox if the fetched value matched
if ( idName === 'post-format-gallery' ) {
$('#gallery-box').show();
}
// show or hide
$('.post-format').click(function(){
idName = $(this).attr('id');
if ( $(this).is(':checked') ) {
if ( idName === 'post-format-gallery' ) {
$('#gallery-box').show();
} else {
$('#gallery-box').hide();
}
}
});