I have two elements in my <svg> element. One appears, one doesn't

后端 未结 1 915
囚心锁ツ
囚心锁ツ 2021-01-28 12:36

One of the use elements is created dynamically, one is created statically. I have written a jsfiddle.

https://jsfiddle.net/rhedin/r0dbf6uy/6/



        
1条回答
  •  深忆病人
    2021-01-28 12:59

    You can't set an xlink:href attribute using setAttribute, you need to use setAttributeNS

    var svgElt = document.getElementById('svg_box');
    var newUse = document.createElementNS("http://www.w3.org/2000/svg", 'use');
    newUse.setAttribute('x', '150px');
    newUse.setAttribute('y', '10px');
    newUse.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#b');
    svgElt.appendChild(newUse);
    
    
        
            
                
                    
                
            
             
        
    
    

    0 讨论(0)
提交回复
热议问题