Why .html() doesn't work with SVG selectors using jquery ?

前端 未结 2 1333
北海茫月
北海茫月 2020-12-30 03:50

Question can some one tell me how can i convert my SVG element to a string ?

i\'m using canvg to convert my SVG to an image.

it has to be re

2条回答
  •  -上瘾入骨i
    2020-12-30 04:29

    As far as I can recall jQuery's .html() makes use of innerHTML which is meant for html, not svg. SVG's are xml documents, so you can use XMLSerializer()

    var svg = document.getElementById('svg_root'); // or whatever you call it
    var serializer = new XMLSerializer();
    var str = serializer.serializeToString(svg);
    

提交回复
热议问题