Run the Javascript function when the contents of the object are loaded

How to run Javascript function when loading <object> content? The DOMContentLoaded event fires before that and things that rely on it like JQuery $() similar way.

Compare this to this . The first example fails because the function is executed when the external SVG has not been loaded. The second example is polling for elements that he wants to change, and only then executes the corresponding code and succeeds.

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

+4
source share
2 answers

Does working with onload DomEvent work?

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

see mine here

+1
source

You should use the onload / ready jquery event - http://api.jquery.com/ready/

 $('#circles').ready(function(){ changeColor(); });` 
0
source

Source: https://habr.com/ru/post/1487774/


All Articles