开发者

How to call a Javascript after a div is replaced?

开发者 https://www.devze.com 2023-01-05 19:35 出处:网络
I dynamically have to call a Javascript after atag is rendered. Is it possible? I am doing some Ajax call which on return should repaint a DIV tag. And it is repaintin开发者_如何学运维g successfully.

I dynamically have to call a Javascript after a tag is rendered. Is it possible? I am doing some Ajax call which on return should repaint a DIV tag. And it is repaintin开发者_如何学运维g successfully. I need to fire a Javascript method AFTER the DIV tag is repainted. How to do that?

Thanks


Short answer: directly it ain't possible (there is no "repaint" or "change" event on DIVs).

However using jQuery or other JS framework that supports custom events you could add an event listener on the div and fire an event in your AJAX call (i suppose it the onSuccess function; so as the last action inside fire custom event).

Even more simply you could just call the desired JavaScript method after you finish changing your DIV.


// I am doing some Ajax call 
function ajax( url ) {
    xmlHttp.onreadystatechange = function () {
       // ...
    };

    // which on return should repaint a DIV tag. 
    div.modify();

    // I need to fire a Javascript method AFTER the DIV tag is repainted.
    javascriptMethod();
}

Or am I missing something here? :) Maybe you want to do the painting thing when the request is finished, but still i don't see any problem here.

0

精彩评论

暂无评论...
验证码 换一张
取 消