Title: Extra JS script loads but doesn&#039;t work
Last modified: August 30, 2016

---

# Extra JS script loads but doesn't work

 *  [laonikoss](https://wordpress.org/support/users/laonikoss/)
 * (@laonikoss)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/extra-js-script-loads-but-doesnt-work/)
 * OK – correction to my previous post. Here’s the current problem now:
 * I have a js script that I want to load to the page. If I hard-code it onto the
   <head> section of header.php (including loading an external minified jquery, 
   [http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js](http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js))
   it works just fine.
 * However, if I remove the link to the external jquery file, it stops working.
 * If I try to load the script through wp_enqueue (functions.php), it loads just
   fine (I can see it loaded on <head>, and if I click on the link it opens the 
   file, so it links to the correct file), but it still doesn’t work.
 * What could be the problem?
 * Here is the original script:
 *     ```
       $(function() {
           $(window).on('scroll', function() {
               $('#par_background').css('margin-top', $(window).scrollTop() * -.3);
           });
       });
   
        $(document).ready(function () {
           $(window).bind('scroll', function () {
               var distance = 50;
               if ($(window).scrollTop() > distance) {
                   $('nav').addClass('scrolled');
               } else {
                   $('nav').removeClass('scrolled');
               }
           });
       });
       ```
   
 * And here’s the modified content of test.js file, formatted to load with wp_enqueue(
   but I am not confident at all if this is the correct formatting, not an expert
   with JS):
 *     ```
       jQuery(function() {
           $(window).on('scroll', function() {
               $('#par_background').css('margin-top', $(window).scrollTop() * -.3);
           });
       });
   
       jQuery(function () {
           $(window).bind('scroll', function () {
               var distance = 50;
               if ($(window).scrollTop() > distance) {
                   $('nav').addClass('scrolled');
               } else {
                   $('nav').removeClass('scrolled');
               }
           });
       });
       ```
   
 * Any help would be appreciated!

The topic ‘Extra JS script loads but doesn't work’ is closed to new replies.

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [load](https://wordpress.org/support/topic-tag/load/)
 * [problem](https://wordpress.org/support/topic-tag/problem/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * 0 replies
 * 1 participant
 * Last reply from: [laonikoss](https://wordpress.org/support/users/laonikoss/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/extra-js-script-loads-but-doesnt-work/)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
