0

Is it possible to use element onload after a reRendering of a div?

My div: populatedChart is reRendered after a button click and is populated with data. Once the div is loaded with the data, I want to check for specific information and act upon that information. My thought was to do this with an onload function. But it is not working as I expected. So I am not sure if it is even possible. My hunch is that the onload can only read the function on the initial page load, and not the reRender load. Does anyone have any insight?

<div class="tableOP" id="populatedChart" onload="populatedChartOnload">
  <div class="rowOP headerOP greenOP">
     <div class="cell cheaderOP panel-heading green-panel">
     This is your Report
     </div>
   </div>
  <div class="rowOP oddOP">
     <div class="cellOP companyname paddingStyleCompName" id="blankComp">
     {!bvs.Status__c}
     </div>
  </div>
</div>

function populatedChartOnload(){                                
   if ('{!bvs.Status__c}' != 'Completed') { 
   document.getElementById("populatedChart").style.display = "none";
   } 
} 

My second thought is that perhaps the data is not loading quick enough for the JS to see it. The {!bvs.Status__c} needs to be full loaded for the JS to be able to function.

UPDATE: Items I have attempted already:

window.addEventListener('DOMContentLoaded', function() {
    if ('{!bvs.Status__c}' == 'Completed') {
    document.getElementById("oldPullreportbutton").style.display = "none";
    }
});      

and

window.onload = function(){
    populatedChartOnload()
};

function populatedChartOnload(){                                
    if ('{!bvs.Status__c}' != 'Complete') { 
      document.getElementById("populatedChart").style.display = "none";
    } 
}
3
  • 1
    you need to use either jQuery .ready(), window.onLoad() or put your script statements at the end of your markup.
    – Eric
    Nov 14 '16 at 15:23
  • @Eric I have tried that but once the reRender happens, the div is refreshed and it pops back up. I have also tried eventListeners with 'DOMContentLoaded' with no success. Once the reRender happens it sets everything back to square one and the JS is not run again.
    – Olivia
    Nov 14 '16 at 15:39
  • @Oliva, I do not see anything in your code that can be rerendered. But, rather than doing what you are doing change the tableOP div to an outputpanel and add a rendered="{!bvs.Status__c != 'Completed}". then it will only render when the status is not completed regardless of rerender. The downside of JS hiding is the element may briefly appear. If you must use JS then put the script before the closing tag of the rerendered element
    – Eric
    Nov 14 '16 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.