Reputation: 53
So I am using the "tabs" widget in elementor pro. I need the page to start in a particular tab on load. I figured I can do that using:
document.getElementById('tab-id').click();
but I need this js code to run after the page has loaded completely. I tried to use "defer" but that didn't work.
Upvotes: 1
Views: 2693
Reputation: 53
So I searched around a bit and found this solution:
<script defer="defer"
type="text/javascript" >
inite=0;
setInterval(function(){
if (document.readyState == "complete" && inite == 0 ) {
document.getElementById('elementor-tab-title-2082').click();
inite++;
}
}, 500);
</script>
I added this by simply adding the code to a "HTML" widget at the end of the page.
So what this does is every half second a script runs to check if the page is fully loaded by using document.readyState.
once the page is ready inite gets nonzero and tab gets clicked.
working perfectly..
Upvotes: 3