2013-12-16 154 views
2

我在SVG中动态地将<title>插入到我的组中,但其效果不起作用。该元素被添加到适当的位置和一切,但我的组没有得到一个工具提示。手动插入到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/

+1

请张贴代码在实际的问题。 – Doorknob

回答

3

你没有建立适当的SVG元素,而是一个DOM元素,你要做的

var title = document.createElementNS('http://www.w3.org/2000/svg', 'title'); 

FIDDLE