I added this bit of code to my header.php file:
<script type="text/javascript">
$(document).ready(function() {
if( $('div').hasClass('icheckbox') && $('div').hasClass('disabled') ) {
$('div').parent().addClass('hide_empty');
}
});
</script>
My goal is to add the class .hide_empty to the parent of all div elements that have a class .icheckbox AND a class .disabled, in that order, with no other classes. The parent of these div elements is a li element in all cases.
I checked many answers to related questions and tried many variations, but whatever cariation I use, the class .hide_empty is never added to the parent li element.
What am I doing wrong here?
Thanks to the input of both @Andrea and @dhirenpatel22 I came up with the following working code:
In my footer.php
I added:
<?php
function hide_empty_terms() { ?>
<script type="text/javascript">
jQuery(window).load(function() {
jQuery(".icheckbox.disabled").each(function() {
jQuery(this).parent('li').addClass('hide_empty');
});
});
</script>
<?php }
add_action('wp_footer', 'hide_empty_terms');
?>
right before <?php wp_footer(); ?>
.
This actually adds the class hide_empty
to the parent li
element of <div class="icheckbox disabled">
.