Title: adding javascript and using javascript
Last modified: August 20, 2016

---

# adding javascript and using javascript

 *  [henrylemmon](https://wordpress.org/support/users/henrylemmon/)
 * (@henrylemmon)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/adding-javascript-and-using-javascript/)
 * Hello,
    I am using two scripts on my site they are enqueue in the functions file
   of my child theme using the:
 *     ```
       <?php
       add_action('init', 'loadJs');
   
       function loadJs() {
       	if (!is_admin()) {
   
       		wp_register_script('jquery.imgpreload.min',
       		get_stylesheet_directory_uri() . '/js/farinspace/jquery.imgpreload.min.js');
          		wp_enqueue_script('jquery.imgpreload.min');	
   
       		wp_register_script('marquee',
       		get_stylesheet_directory_uri() . '/js/marquee.js',
       		array('jquery') );
          		wp_enqueue_script('marquee');
       	}
       }
       ?>
       ```
   
 * the only way I can get these to run is if I do a find and replace in both js 
   files and use find $ and replace with jQuery, so now is that correct, or am I
   setting myself for conflicts?
    Thanx a million, henryLemmon

Viewing 1 replies (of 1 total)

 *  Thread Starter [henrylemmon](https://wordpress.org/support/users/henrylemmon/)
 * (@henrylemmon)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/adding-javascript-and-using-javascript/#post-3381360)
 * correct me if i am wrong:
    I changed:
 *     ```
       $(document).ready(function()
       to
       jQuery(document).ready(function($)
       ```
   
 * and I added the var below as a global to handle all the instances of the $ that
   was not insice of the document.ready function.
 *     ```
       var $ = jQuery;
       ```
   
 * Is that what I am supposed to do? I know it works this way, it also works if 
   I change all the $ to jQuery, but I did not think that was right, so let me know.
   
   Thank you! henrylemmon

Viewing 1 replies (of 1 total)

The topic ‘adding javascript and using javascript’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [henrylemmon](https://wordpress.org/support/users/henrylemmon/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/adding-javascript-and-using-javascript/#post-3381360)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
