outerHtml为IE中的SVG元素返回undefined [英] outerHtml returns undefined for SVG elements in IE

查看:279
本文介绍了outerHtml为IE中的SVG元素返回undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

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

我在b上触发鼠标移动事件

i have trigger mouse move event on b

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

这是在chrome工作,但在IE中无法解决这个问题。

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

请找到JSFiddle链接: http://jsfiddle.net/r8v70Lnk/

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

警告框只会在Chrome中显示但不会在IE中显示..

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

推荐答案

不知道它是否适合您,但我通常会这样做:

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")

这篇关于outerHtml为IE中的SVG元素返回undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆