Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Javascript function when object content has been loaded

How do I run a Javascript function when the content of an <object> has been loaded? The DOMContentLoaded event fires before that, and things that rely on it like JQuery's $() likewise.

Compare this to this. The first example fails because the function is executed when the external SVG hasn't been loaded. The second example polls for the elements it wants to change and only then executes the relevant code, and succeeds.

Polling works in practice, but is there a better solution for this? Ideally there would be an event fired that I can use.

like image 789
Lars Kotthoff Avatar asked Jun 27 '13 15:06

Lars Kotthoff


1 Answers

Does using the onload DomEvent work?

<object onload="changeColor()" data="circles.svg" type="image/svg+xml" id="circles"></object>

see my it here

like image 121
Braden Avatar answered Sep 29 '22 23:09

Braden