Grow your CSS skills. Land your dream job.

Clear jQuery cache on page refresh?

  • # April 4, 2013 at 8:36 am

    Hi,

    Curious if there is a preferred method for clearing/resetting the DOM cache for jQuery events…

    I’m dynamically adding an _active_ class to a series of elements with jQuery. If the page is refreshed, the _active_ class remains on the current element instead of starting over again.

    I’ve attempted to solve this by adding the following meta tags to the html, but it did not solve anything.


    Anyone have a suggestion for tackling this issue? Thank You.

    # April 4, 2013 at 9:54 am

    I’ve never heard of something like that, got a demo?

    # April 4, 2013 at 10:14 am

    Hmm, I’m not seeing the issue you are describing. I have seen something similar is Firefox when using form elements – a refresh would not reset the input values and cause a whole bunch of problems – but nothing like this with class names.

    The [demo you shared](http://jsfiddle.net/6TCdY/) is similar to a [demo I have using my visualNav plugin](http://mottie.github.com/visualNav/stepper.html). Are you seeing the same issue there?

    # April 4, 2013 at 10:40 am

    @mottie

    Yes…I’m seeing the issue on your demo also. In short…when the browser is refreshed, the scroll position remains in the same spot, instead of starting at the top again. Any idea how to solve that?

    # April 4, 2013 at 11:04 am

    This is actually standard browser behavior and not an issue with jQuery DOM cache. For anyone interested, I solved this by adding the following code to jQuery. Essentially it will reset the page/scroll position to the top after a refresh.

    $(document).ready(function(){
    $(‘html, body’).animate({scrollTop:0}, 1);
    });

    # April 4, 2013 at 11:27 am

    Oh! You mean the scroll position. The original description made it seem like it was a problem with the class name not being correct.

    # April 4, 2013 at 11:33 am

    Yea…my mistake. Apologies for the confusion.

    # April 4, 2013 at 12:21 pm

    I’ve never been a fan of overwriting a browser default, keep that in mind!

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".