简体   繁体   中英

Is there any way to refresh the DOM after a time without a click or any other event?

I was wondering if there is any way to refresh the DOM, lets say with a function inside a timeout without need an event? like a click or something?

I basically need to go over all divs with a certain class, those divs are inserted by a javascript (I cant modify it) and I want to, after they are inserted, modify some content... is there any way to do this?

This is one way:

setInterval(function () {

    $('.certain-class').each(function () {
        $(this).html('modify some content');
    });

}, 2000); // every 2 seconds

If it should only run once after a delay, use setTimeout instead of setInterval

您可以使用window.setInterval(function, delay)n毫秒执行一次function

I know you said without an event, but I think you mean without user interaction. If that is the case, is this a place where you could use the endrequest event? This event happens after an asynchronous postback is finished and control goes back to the browser, so if that other javascript is executed as part of an async postback, you could use this to tell the browser to run your code after that other one is all done. See here :

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler)

where endRequestHandler is your code that is going to examine/change the DOM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM