Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

how to run a function several times after loading the page (alongwith search facets filter) when filter searching for content in aem

Avatar

Level 2

I want to remove spans of granite-omnisearch-facet-labelcount / granite-omnisearch-facet-count from search facets having count "0" after resulting content is displayed but the problem is when i run my function after foundation-contentloaded event i am unable to get these spans because page is not loaded properly. Most probably spans of counts are merging with coral-checkboxes after page load event so that is why they are not extracting properly please guide i am new to AEM.

3 Replies

Avatar

Community Advisor

I did not undertsand your objective clearly here, but I think you want to run your JS/Jquery code after the pages loads completely .

 

If that you are looking for then you can use below code

 

you can have $(document).ready() multiple times in a page. The code gets run in the sequence in which it appears.

You can use the $(window).load() event for your code since this happens after the page is fully loaded and all the code in the various $(document).ready() handlers have finished running.

$(window).load(function(){
  //your code here
});

 

And if you want to delay more

use setTimeout jquery function write your code , Though I personally believe , put this as a last option

 

Or if you looking for something please xplain more in your query

Avatar

Level 2

Well window.load is a good option but what if user selects or deselects any search facet checkbox ??? because i think window.load only run my script when the page is fully loaded manually or by any means like submitting or entering anything but i want my script to run every time the user selects or selects any search facet checkbox.. is it possible ??? if yes then please guide how can I do it and if not then please guide any alternative for this...

Avatar

Level 2

Well window.load is a good option but what if user selects or deselects any search facet checkbox ??? because i think window.load only run my script when the page is fully loaded manually or by any means like submitting or entering anything but i want my script to run every time the user selects or selects any search facet checkbox.. is it possible ??? if yes then please guide how can I do it and if not then please guide any alternative for this...