Reputation: 5858
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?
Upvotes: 0
Views: 84
Reputation:
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.
Upvotes: 0
Reputation: 2995
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
Upvotes: 1
Reputation: 971
You can use window.setInterval(function, delay)
to execute a function
every n milliseconds.
Upvotes: 0