Script not working in WordPress Header.php

I have placed the following script:

 if ( jQuery(window).width() > 1026) {   
  jQuery('.widgetable').scrollToFixed({marginTop:80,zIndex:9});
 }

But when i refresh the page the side bar is not scrolling, when i place this code into the chrome console it works without problem.

Read More

Thanks
Alex

Related posts

Leave a Reply

1 comment

  1. When you’re placing script inside your header.php file, its always good to wrap it inside document.ready event handler function.

    jQuery(function() {
     if ( jQuery(window).width() > 1026) {   
                jQuery('.widgetable').scrollToFixed({marginTop:80,zIndex:9});
            }
    });
    

    This will make sure that the DOM is available when the function executes. Also the scrollToFixed plugin would have also finished loading by then.