Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

onload innerhtml

3 views
Skip to first unread message

Andrew Poulos

unread,
Sep 13, 2009, 9:28:55 PM9/13/09
to
I'm modifying the contents of a DIV using innerHTML and after the
modification I need to run some javascript on it. Is there an equivalent
of an onload event I can use with innerHTML?

Andrew Poulos

Thomas 'PointedEars' Lahn

unread,
Sep 14, 2009, 9:06:18 AM9/14/09
to
Andrew Poulos wrot:

> I'm modifying the contents of a DIV using innerHTML and after the
> modification I need to run some javascript on it. Is there an equivalent
> of an onload event I can use with innerHTML?

Counter-question: Is there reason to believe that execution will continue
after the assignment before the content has changed? If no, simply put the
code after the assignment; if yes, it depends on the runtime environment
(RTFM¹). If that environment does not support the event, you need to resort
to property polling with window.setInterval() or, in shorter intervals,
preferably with self-calling window.setTimeout().

That said, you should not be using the proprietary `innerHTML' property, but
standards-compliant W3C DOM Level 2+ methods instead.²


PointedEars
___________
¹ <http://www.w3.org/TR/DOM-Level-3-Events/#events-mutationevents>
<https://developer.mozilla.org/En/Listening_to_events#Simple_DOM.c2.a0events>
<http://msdn.microsoft.com/en-us/library/ms533051%28VS.85%29.aspx>
² <http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document>
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300...@news.demon.co.uk> (2004)

0 new messages