# Javascript menu

**URL:** <https://forum.pinegrow.com/t/javascript-menu/5041>\
**Category:** Javascript\
**Created:** [February 28, 2021, 10:17am UTC](https://forum.pinegrow.com/t/javascript-menu/5041 "2021-02-28T10:17:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevegun1975](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@stevegun1975](https://forum.pinegrow.com/u/stevegun1975)\
**Post date:** [February 28, 2021, 10:17am UTC](https://forum.pinegrow.com/t/javascript-menu/5041/1 "2021-02-28T10:17:36Z")

</div>

I have created a small javascript file and linked into the sheet, the javascript triggers a class change in nav menu together with css changes the menu size and colour when you scroll from the top of the page.

It works fine when running the html files but when I export to wordpress the javascript is not working.  
I have checked the function.php and the javascript file is linked.

Any help would be great…

 ![Screenshot 2021-02-28 at 10.21.32](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/9/95a061364ad39522d469de55a653be46b44f463e.png)

---

<div class="post-metadata">

**Author:** ![RobM](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@RobM](https://forum.pinegrow.com/u/RobM)\
**Post date:** [February 28, 2021, 11:01am UTC](https://forum.pinegrow.com/t/javascript-menu/5041/2 "2021-02-28T11:01:50Z")

</div>

Hi @stevegun1975,  
Just a check on one thing - when you say the javascript file is linked, you mean it is enqueued, correct? You can see it loaded onto the end page?

That aside, if we assume your script is being loaded you are going to run into a problem with jQuery. Your script above isn’t in plain JS. In WordPress, jQuery uses “compatibility” mode. This means that you can’t use the `$` shortcut directly like you are in this example. Instead, one approach is to change all of the `$` into`jQuery`.  
Another, probably better, approach is to wrap your script in a ready function.

```auto
jQuery(document).ready(function($){ your code});

```

Hope this helps,  
Bob

---

<div class="post-metadata">

**Author:** ![stevegun1975](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@stevegun1975](https://forum.pinegrow.com/u/stevegun1975)\
**Post date:** [February 28, 2021, 11:10am UTC](https://forum.pinegrow.com/t/javascript-menu/5041/3 "2021-02-28T11:10:16Z")

</div>

> [@RobM](#):
>
> `jQuery(document).ready(function($){ your code});`

Thanks bob, thanks you. It’s works fine now.
