Support

Account

Home Forums Backend Issues (wp-admin) jQuery selector not working when trying to interact with an ACF field admin Reply To: jQuery selector not working when trying to interact with an ACF field admin

  • Well, I feel a bit like an idiot, but for anyone else having this issue… The problem is that WP’s admin side runs jQuery in no-conflict mode – meaning you can’t use $ to access jQuery (amoungst other things).

    My updated JS to affect the checkboxes looks like this:

    jQuery(document).ready(function(){
    	// Check and uncheck children when parent is clicked
    	jQuery('ul.categorychecklist > li > label > :checkbox').change(function() {
    		jQuery(this).parent().parent().children('ul.children').children('li').children('label').children(':checkbox').attr('checked', this.checked);
    	});
    });

    Using jQuery instead of the already reserved $ selector fixes the problem, and allows the code to run properly.