Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  61] [ 2]  / answers: 1 / hits: 29279  / 13 Years ago, tue, december 13, 2011, 12:00:00

I have an SVG file, and I don't want to paste it inside the HTML file because, well, it gets messy.
So after consulting with w3schools, embed tag seemed the safest way to include an external SVG file into HTML.



<embed src=path_to_svg type=image/svg+xml id='svgsource' />


However, I need to access the svg elements through DOM via javascript in the main html file. Unfortunately neither



document.getElementById('my_svg_id')


nor



document.getElementById('svgsource').contentDocument


works in any browser. Using object tag doesn't do the trick either.


More From » html

 Answers
12

Complete about turn!



Turns out you can, see this link: http://xn--dahlstrm-t4a.net/svg/html/get-embedded-svg-document-script.html



(Also, go and up vote some of Erik Dahlström's other answers to give him some points for me hijacking his answer!)


[#88573] Monday, December 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irvingcarloe

Total Points: 677
Total Questions: 109
Total Answers: 96

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
irvingcarloe questions
Wed, Mar 31, 21, 00:00, 3 Years ago
Tue, Aug 4, 20, 00:00, 4 Years ago
Fri, Jul 3, 20, 00:00, 4 Years ago
;