Can’t seem to check off a category checkbox with jquery?

Question

I’ve got the following simple jquery test script to test if I can check off a category box in the right sidebar when creating a new post:

jQuery(document).ready(function($) {
  console.log('js file loaded');
  // Check the "Public" checkbox by default
  $('#inspector-checkbox-control-4').prop('checked', true);
});

I get the console message but the box is never checked. I have the correct id. This probably has something to do with load order. I’m loadig the jquery from a plugin with:

function pu_my_plugin_scripts() {
    wp_enqueue_script( 'my-plugin-script', plugins_url( './js/my-plugin-script.js', __FILE__ ), array( 'jquery' ), null, true );
}
add_action( 'admin_enqueue_scripts', 'pu_my_plugin_scripts' );

0
StevieD 4 weeks 2023-02-19T14:08:23-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse