outerHtml returns undefined for SVG elements in IE

2019-04-23 17:31发布

Here is my code

<svg id="a" height="210" width="400">
  <path id="b" d="M150 0 L75 200 L225 200 Z" />
</svg>

i have trigger mouse move event on b

   $("#b").hover(function() {
        alert($(this)[0].outerHTML);
    });

this was working in chrome but not working in IE how can i solve this..

please find the JSFiddle link : http://jsfiddle.net/r8v70Lnk/

alert box will show only in chrome but not in IE..

1条回答
beautiful°
2楼-- · 2019-04-23 18:08

Dont know if it is a solution for you but i usually do it like:

new XMLSerializer().serializeToString(document.querySelector('#b'))

If you want to parse the string again and insert the node in your document:

new DOMParser().parseFromString(svgString, "image/svg+xml")
查看更多
登录 后发表回答