Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External SVG file is NOT getting loaded using JQuery

Tags:

jquery

svg

I am trying to load simple svg file in HTML5 using JQuery. But i dont seem to get that effect in my page. Please help me solve this.

I have browsed and found the way, but it is not working for me. See my code below:

SVG file: (Sample.svg)

<?xml version="1.0" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <circle cx="100" cy="50" r="40" stroke="black"
  stroke-width="2" fill="red" />
</svg>

Script:

$(document).ready(function(){
 $('#svgfile').svg({loadURL: 'Sample.svg'});
}

MyHtml.html:

<div id="svgfile" style="background:#9b0141;width:400px; height: 400px;">
like image 714
Vignesh Avatar asked Dec 09 '22 13:12

Vignesh


1 Answers

$('#svgfile').svg({loadURL: 'Sample.svg'}); is not valid jQuery unless you are using some plugin you haven't mentioned.

try

$('#svgfile').load('Sample.svg');

like image 164
DGS Avatar answered Jan 22 '23 16:01

DGS