Title: jQuery in admin panel not triggering function
Last modified: August 20, 2016

---

# jQuery in admin panel not triggering function

 *  Resolved [PeterShea](https://wordpress.org/support/users/petershea/)
 * (@petershea)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/jquery-in-admin-panel-not-triggering-function/)
 * I’ve been struggling for some time with this … I just can’t seem to get functions
   to be triggered from within the admin panel for a plugin I’m writing! I’ve pared
   it down to this …
 * My HTML code is:
 *     ```
       <p>
         <label for="psw_upload_image">
         <input id="psw_upload_image" type="text" size="36" name="psw_upload_image" value="" />
         <input id="psw_upload_image_button" type="button" value="Upload Image" />
         <br />Enter an URL or upload an image for the banner.
         </label>
       </p>
       ```
   
 * The scripts are in the pluginn’s functions file as follows:
 *     ```
       function psw_admin_scripts() {
       	wp_enqueue_script('media-upload');
       	wp_enqueue_script('thickbox');
       	wp_register_script('psw-upload', WP_PLUGIN_URL.'/psw-base/code/psw-script.js', array('jquery','media-upload','thickbox'));
       	wp_enqueue_script('psw-upload');
       }
   
       function psw_admin_styles() {
       	wp_enqueue_style('thickbox');
       }
   
       add_action('admin_print_scripts', 'psw_admin_scripts');
       add_action('admin_print_styles', 'psw_admin_styles');
       ```
   
 * The JavaScript file mentioned above contains the following (just debug code at
   the moment until I can figure out why this isn’t working!):
 *     ```
       jQuery(document).ready
       	(function()
       		{
       		alert('A');
       		jQuery('#psw_upload_image_button').click
       				(function()
       					{
       					alert("Hello");
       					}
       				);
       		alert('B');
       		}
       	);
       ```
   
 * I’ve used firebug to put breakpoints into the code above, and everything gets
   called correctly when the page loads, **but**, when I click the button, nothing
   happens (obviously I’m expecting a box with “Hello!” to appear.
 * The two boxes with “A” and “B” appear OK when the page is loaded, just not my“
   Hello!” box :(.
 * Help!

Viewing 1 replies (of 1 total)

 *  Thread Starter [PeterShea](https://wordpress.org/support/users/petershea/)
 * (@petershea)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/jquery-in-admin-panel-not-triggering-function/#post-2968430)
 * In case anyone else is struggling with this, I just managed to find the answer
   to my problem. jQuery is being soooooo picky! if the “#psw_upload_image_button”
   is replaced with “input#psw_upload_image_button”, then the event is triggered
   on clicking the button!

Viewing 1 replies (of 1 total)

The topic ‘jQuery in admin panel not triggering function’ is closed to new replies.

## Tags

 * [admin](https://wordpress.org/support/topic-tag/admin/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [PeterShea](https://wordpress.org/support/users/petershea/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/jquery-in-admin-panel-not-triggering-function/#post-2968430)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
