I am trying to create a JavaScript file that uses jQuery to create an on-click event for a button.
I can't however get it to work and I'm not even sure if the script is loading. I have searched for it in the page source but it is not there so that would suggest that it is not loading at all. I am new to plugins and jQuery but I followed a tutorial and copied the below code.
<?php
/*
Plugin Name: PansHousePlugin
Plugin URI: http://pans-house.com
Description: Adds OnClick and Scroll Functionality
Version: 1.0
Author: Paul Leppard
Author URI: http://pans-house.com
*/
add_action('wp_enqueue_scripts', 'load_js');
function load_js() {
wp_register_script('click_scroll', plugins_url( 'click_scroll.js', __FILE__), array( 'jQuery'), true );
wp_enqueue_script('click_scroll');
}
?>
and the click_scroll.js file which is in the same folder as the plugin.php file
(function($){
$(function(){
$("#gopricing").hide();
$(".showpricingbutton").on("click", function(){
$("#gopricing").toggle();
});
});
}(jQuery));
Like I said this is exactly as the tutorial says. The plugin is activated without any errors but the div with the id gopricing is not hidden and the button does not do anything on clicking it, so I am assuming the script has not been loaded.
Thanks