php - wordpress how to add javascript to wp-admin

one text

Solution:

First of all, you've defined the chcol function in your javascript file BUT YOU HAVE NEVER CALLED/USED IT!

Second point in your code, when you try to inject your js file to admin (or any other page on wordpress), first check whether you're actually on that page or not. Although, admin_enqueue_scripts action hook should do the trick for you.

For example, in your case, first check whether you're actually on the admin panel or not then inject/enqueue your js file! It never hurts to double check!!!

function my_enqueue() {
  if(is_admin()){ // if it returns true 
    // Then run wp_enqueue_script() function!
  }
}

add_action( 'admin_enqueue_scripts', 'my_enqueue' );

Source