Boilerplate – Run js function onClick button

Question

I am using the boilerplate generator for first time and I have a problem.

On my edit post page, I have created a custom button like this:

admin/admin-class-myPlugin-admin.php

    public function custom_button($post){
     if($post->post_type == 'match'){
      echo '<div id="major-publishing-actions" style="overflow:hidden">';
      echo '<div id="publishing-action">';
      echo "<input type='submit' accesskey='p' tabindex='5' value='Import Match' class='button-primary' id='custom' name='publish'>";
      echo '</div>';
      echo '</div>';
   }
    
}

And I have registered this button like this:

includes/class-myPlugin.php

private function define_admin_hooks() {

    $plugin_admin = new MyPlugin_Admin( $this->get_plugin_name(), $this->get_version() );

    $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    $this->loader->add_action( 'post_submitbox_misc_actions', $plugin_admin, 'custom_button' );
}

There is a js file inside admin folder and I think it’s being called like this:

admin/admin-class-myPlugin-admin.php

wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/myPlugin-admin.js', array( 'jquery' ), $this->version, false );

What I want is to run a JS function onClick button in my HTML div element.

onClick=myTestFunction()

myTestFunction(){
  window.alert('YAY');
}

Anyone can help please?

0
marissalianam 1 month 0 Answers 6 views 0

Leave an answer