Title: jQuery code not working
Last modified: September 1, 2016

---

# jQuery code not working

 *  Resolved [onadras](https://wordpress.org/support/users/onadras/)
 * (@onadras)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/jquery-code-not-working/)
 * Hi, I’m trying to manually implement a sidebar element that becomes fixed after
   some scrolling. In order to do it, I’m using few lines of jQuery that after scroll
   add a class with position:fixed property to the element, and on a testing environment
   it works fine.
    However when implementing it on wordpress, it doesn’t seem to
   work. I put the following script in the custom javascript section of my theme
   admin panel, it seems to be loaded on the frontend but nothing happens.
 *     ```
       $(window).scroll(function(){
             if ($(this).scrollTop() > 235) {
                 $('#sidebar-2').addClass('fix-it');
             } else {
                 $('#sidebar-2').removeClass('fix-it');
             }
       });
       ```
   
 * Here’s also some dummy code to explain what I’m trying to accomplish: [fiddle](http://jsfiddle.net/FyEGN/858/)
 * Am I missing something? Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [ikaring](https://wordpress.org/support/users/ikaring/)
 * (@ikaring)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/jquery-code-not-working/#post-7650983)
 * Hi.
    What if replace all `$` with `jQuery`?
 * Or, wrap whole your code with:
 *     ```
       (function($){
           //your code here
       })(jQuery);
       ```
   
 *  Thread Starter [onadras](https://wordpress.org/support/users/onadras/)
 * (@onadras)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/jquery-code-not-working/#post-7650998)
 * Yes it works by replacing $ with jQuery, thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘jQuery code not working’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [onadras](https://wordpress.org/support/users/onadras/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/jquery-code-not-working/#post-7650998)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
