4

I have a snippet of javascript which adds classes elements on the page once loaded, I have noticed that while reRendering the page these js changes are lost.

How can I have them reapplied/intact on rerender?

JS Example:

$( document ).ready(function() {        
          $('[data-filter="open"]').addClass('active');
...
1
  • Pls include the page that you are rerendering. Are you rerendering only part of it, or the whole page? Oct 15, 2014 at 13:00

1 Answer 1

6

Providing this script is not in the part of the page being re-rendered:

<script>
// Provide a function that can be used in oncomplete
function myInit() {
    $( document ).ready(function() {        
        $('[data-filter="open"]').addClass('active');
        ...
    };
}
// Initialise when the page first loads by calling the function
myInit();
</script>

you can invoke the initialisation code after the Ajax request completes by using the oncomplete attribute like this:

<apex:commandButton value="Do Something"
        reRender="something"
        oncomplete="myInit();"
        />

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .