最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - outerHtml returns undefined for SVG elements in IE - Stack Overflow

programmeradmin3浏览0评论

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 : /

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

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/r8v70Lnk/

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

Share Improve this question edited Feb 9, 2019 at 1:07 Splaktar 5,9045 gold badges45 silver badges75 bronze badges asked Apr 27, 2015 at 5:45 Akbar BashaAkbar Basha 1,1981 gold badge17 silver badges40 bronze badges 7
  • 6 Possibly related stackoverflow./questions/12592417/… – Miguel Commented Apr 27, 2015 at 5:45
  • maybe you don't need $(this)[0]? – filype Commented Apr 27, 2015 at 5:48
  • What do you mean by "not working"? – Maurice Perry Commented Apr 27, 2015 at 5:48
  • the exact path can be log (console) in chrome but same sample in IE it can be logged as undefined – Akbar Basha Commented Apr 27, 2015 at 5:51
  • @Filype is right, btw: $(this)[0].outerHTML === this.outerHTML – Maurice Perry Commented Apr 27, 2015 at 5:52
 |  Show 2 more ments

1 Answer 1

Reset to default 9

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")
发布评论

评论列表(0)

  1. 暂无评论