views:

48

answers:

2

Hi,

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 repainting successfully. I need to fire a Javascript method AFTER the DIV tag is repainted. How to do that?

Thanks

+2  A: 

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.

Zergin
+1 a custom event will be the best thing to do here. You'll have to trigger it manually but there simply is no way to do this cross-browser with a native event.
Pekka
+1  A: 
// 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.

galambalazs
Argh!! Thanks dude.. its as simple as that..
Bragboy
no problem.. :)
galambalazs