我正在SVG中动态地将<title>
插入到我的组中,但它的效果不起作用。元素被添加到适当的位置,但我的小组没有得到工具提示。手工插入SVG中的相同元素也起作用。为什么我的动态插入的不是?
function setuptooltip() {
var shadowlegs = document.getElementById('shadow-legs');
var title = document.createElement('title');
var titletext = document.createTextNode("Hi there and greetings!");
title.appendChild(titletext);
// get the first child of shadowlegs, so we can insert before it
var firchild = shadowlegs.firstChild;
// insert before the first child
shadowlegs.insertBefore(title, firchild);
}
这是代码:http://jsfiddle.net/bYjva/
您不是在创建一个合适的SVG元素,而是一个DOM元素,您必须执行
var title = document.createElementNS('http://www.w3.org/2000/svg', 'title');
FIDDLE