Javascript function won't execute
-
I’m having a problem getting a javascript function to execute. I’m using this store locator script. It works perfectly fine in a non-wordpress site, but once I bring it into WordPress, it doesn’t work. The following is in my functions.php page:
function my_map_scripts() { if ( is_page_template( 'template-project-map.php' ) ) { wp_enqueue_script( 'jplist-custom-script', get_stylesheet_directory_uri() . '/js/jplist.min.js', array( 'jquery' ) ); wp_enqueue_script( 'jlocator-custom-script', get_stylesheet_directory_uri() . '/js/jlocator.min.js', array( 'jquery' ) ); wp_enqueue_script( 'jlocator-activate-script', get_stylesheet_directory_uri() . '/js/jlocator.activate.js', array( 'jquery' ) ); wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js' ); } } add_action( 'wp_enqueue_scripts', 'my_map_scripts' );
The jlocator.activate.js file contains the following:
jQuery(document).ready(function(){ jQuery('#jlocator').jlocator(); });
This code will not execute. I feel like there is some type of problem with jlocator(), as this line simply won’t execute. Also, if I put an alert in the ready function, it doesn’t execute either, unless I remove jQuery(‘#jlocator’).jlocator();
I checked the error console, and I am getting TypeError: jQuery(…) is not a function, and that is referring to each of my js files. Each one goes to a line that has something like this (function(k){var……….
Am I missing something simple here?
- The topic ‘Javascript function won't execute’ is closed to new replies.