Skip to content
Advertisement

getElementById in SVG document

I wrote a svg file like this:

JavaScript

As in the comment line alert(document); alerts [object SVG document].

But:

JavaScript

alerts null.

I also tried to put svg in an html page, also in an xhtml page, tried more thing but no result for now.

Any idea?

Advertisement

Answer

At the time you call var path=document.getElementById('path1');, the path1 is not defined yet (it comes later on).

You ought to put the code after the path definition.

However I’m not sure if you can put <script> tags inside a <svg>.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement