2
I registered my Javascript file in my plugin but the functions of click
and etc. do not work.
I registered my main plugin file with the action
:
function add_scripts_to_plugin()
{
wp_enqueue_script( 'birthdate_celebrate_js', dirname(__FILE__) . '/includes/assets/js/main.js', array( 'jquery' ));
}
add_action('wp_enqueue_scripts', 'add_scripts_to_plugin');
The Javascript file:
jQuery( function( $ ) {
$('#birthdate_celebrate_send_mails').on('click', function () {
console.log('clicked');
});
});
The plugin loads normally and shows no error in the console or in PHP, but even so the eventListener
click is not added to button.
What is the link to the site for me to view?
– Wendell
I’m developing locally but the link to the repository is this
– RFL
You tried to replace the line
$('#birthdate_celebrate_send_mails')
forjQuery('#birthdate_celebrate_send_mails')
?– Wendell
Yes Wendell, within the function
jQuery
either write down the name or use the$
.– RFL
The button is added to the page after the initial upload?
– Ricardo Moraleida
Yes Ricardo, the function
wp_enqueue_scripts
puts the script in the footer after loading using thewp_footer()
– RFL
Actually Ricardo wanted to know if the button in question is included via some other script, instead of being in the HTML source.
– Dudaskank