jquery's append not working with svg element?

后端 未结 14 2208
北海茫月
北海茫月 2020-11-21 06:28

Assuming this:



 
 

        
14条回答
  •  不知归路
    2020-11-21 06:51

    Found an easy way which works with all browsers I have (Chrome 49, Edge 25, Firefox 44, IE11, Safari 5 [Win], Safari 8 (MacOS)) :

    // Clean svg content (if you want to update the svg's objects)
    // Note : .html('') doesn't works for svg in some browsers
    $('#svgObject').empty();
    // add some objects
    $('#svgObject').append('');
    $('#svgObject').append('');
    
    // Magic happens here: refresh DOM (you must refresh svg's parent for Edge/IE and Safari)
    $('#svgContainer').html($('#svgContainer').html());
    .svgStyle
    {
      fill:cornflowerblue;
      fill-opacity:0.2;
      stroke-width:2;
      stroke-dasharray:5,5;
      stroke:black;
    }
    
    
    
    It works if two shapes (one square and one circle) are displayed above.

提交回复
热议问题