:::: MENU ::::

Magento Tutorial | Magento Blog | Learn Magento 2

Cookies Consent Popup

Showing posts with label How to check if an element has been loaded on a page before running a script in JS?. Show all posts
Showing posts with label How to check if an element has been loaded on a page before running a script in JS?. Show all posts
Sometime we just need to use simple jQuery on checkout page but checkout element bind with knockout js so our jQuery not work smoothly so below is a way to call your jQuery after bind perticular element.

Use below code in your jquery and it will load after binding your element in page.

function waitForElement(query, callback){
    var poops = setInterval(function(){
        if(document.querySelector(query)){    
            clearInterval(poops);
            callback();
        }
    }, 100);
}

waitForElement(".class", function(){
    alert("element is loaded.. do stuff");
});