Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when innerHTML is complete

Tags:

javascript

I've done quite a bit of searching for a solution to this problem but so far haven't found one that works cross browser.

What I need is a raw javascript function which will take an element and run a callback once the innerHTML has successfully been inserted into the dom.

e.g.

    var element = document.getElementById('example');
        element.innerHTML = newhtml;

    waitUntilReady(element, function(){
            //do stuff here...
    });

So just to summarize, I need to be able to check the contents of the element and fire a callback when innerHTML has completed.

Thanks in advance for any help.

like image 929
gordyr Avatar asked Jul 16 '12 22:07

gordyr


1 Answers

There is no need for such a function. Assigning to innerHTML will do so immediately before continuing to run any scripts.

If you really need to delay execution (say to allow the browser to redraw), use setTimeout with a delay of 1 (or other short interval).

like image 70
Niet the Dark Absol Avatar answered Oct 11 '22 13:10

Niet the Dark Absol