I find that if I embed svg in my html then I can access the id's simply:
<svg width="100" height="100">
<circle id='myCircle' cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
Javascript:
$('#myCircle').css('fill','red'); // works fine
But if I load this svg file externally:
<object id='myfile' data="myfile.svg" type="image/svg+xml">
</object>
(and assuming this svg contains the same id/content as above) I cannot do:
$('#myCircle').css('fill','red'); // doesn't work anymore
so I'm wondering how I can access the id's of externally loaded .svg files?
Update:
I tried
var doc = $('#piano')[0].contentDocument; doc.getElementById('#myCircle);
But I get, (I'm using Chrome)
SecurityError: Failed to read the 'contentDocument' property from 'HTMLObjectElement': Blocked a frame with origin "null" from accessing a cross-origin frame.