0

I looked at several topics with a similar problem, however, these solutions did not help me. I have a div, with an object inside. I am trying to get DOM of the svg file, however it returns me null.

var svgobject = document.getElementById("34");
alert(svgobject); //ok
var svgdom = svgobject.contentDocument;  //null
var selector = svgdom.querySelector('svg');

Also, i tried add something like this:

    svgobject.addEventListener("load",function() {
       var svgDoc = mySVG.contentDocument;
       alert("SVG contentDocument Loaded!");
       alert(svgDoc); //null
    }, false);

And the result was the same..

HTML:

<div class="svgGenerator">
    <object id = "34" data="images/generator.svg" type="image/svg+xml"></object>
  </div>

How do i correctly get a contentDocument of my SVG file?

  • 1
    Does this answer your question? [JavaScript accessing inner DOM of SVG](https://stackoverflow.com/questions/11434916/javascript-accessing-inner-dom-of-svg) – jeprubio Mar 31 '20 at 13:51
  • Is generator.svg a valid SVG file. If it isn't then contentDocument will return null. – Robert Longson Mar 31 '20 at 13:57

0 Answers0