javascriptjqueryslimscroll

slimScroll is not defined on Browser Back Button


I have a basic code that uses the jquery.slimscroll, which works perfectly fine on page load. But if I navigate to an inner page and try to go back using the "back" button on browser, I get the following error:

Uncaught TypeError: Object [object Object] has no method 'slimScroll'

I have checked the element's length and confirmed that the object exists. My jQuert is as simple as this:

<script type="text/javascript">
    $("#boxsrchome").slimScroll();
</script>

Note: I tried wrapping the code around $(document).ready() and $(window).load(). And that did not help either.


Solution

  • First, see if jQuery is defined by inputting jQuery in the console. If it is, try this: Try wrapping it in:

    (function($) {
        $("#boxsrchome").slimScroll();
    })(jQuery);
    

    If it isn't, you have a problem with the way you're including your files. Also, make sure you aren't including slimscroll.js in the wrong place, and make sure you're not redefining the jQuery object by using jQuery.noConflict(); anywhere, although, that shouldn't matter with this method.