Accessing a DOM object defined in an external SVG file

后端 未结 4 1059
天命终不由人
天命终不由人 2020-11-29 06:53

SVG standard allows to use and refer external SVG files.

I have a file circle.svg that defines a circle object with id \"the_circle\". From the main SVG

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 07:32

    To supplement @echo-flow's excellent solution with the code in jQuery/Coffeescript:

      $.get '/assets/hexagon.svg', (svgFileData)->
        svgTag = svgFileData.documentElement
        $('body').append(svgTag)
        circle = $('#the_circle')
    

提交回复
热议问题