Reputation: 219
I made a webpage that loads an svg with the object tag
<object id="svgContainer" type="image/svg+xml" data="image.svg">Your browser does not support SVG</object>
and want to display some content dynamically. When I include the svg direct inside the HTML it works fine
<svg id="svgVontainer">
<circle cx="100" cy="100" r="2" id="edit" />
</svg>
JavaScript:
$(function() {
$("#edit").hide();
});
But when I try the same code with the object
it doesn't work.
Does someone know that problem and how to fix it?
EDIT: Here a jsFiddle so you can see what I mean http://jsfiddle.net/Ue7m7/.
Upvotes: 0
Views: 788
Reputation: 658
If you only want to hide/show the SVG object
tag, you can do it as usual with jQuery.
But if you want to deal with the content of the 'remote' SVG object
, this seems to be possible but with some restrictions:
iframe
tag). object
tags with JS you need to have extra JS code, as shown here. I think with jQuery you could try $("#rect1").get(0).getSVGDocument()
or something similar (I haven't tested that snippet). Check that link to learn more.Upvotes: 2
Reputation: 509
Try some vanilla instead
function hide(id){
document.getElementById(id).style.display = "none";
}
function show(id){
if(document.getElementById(id).style.display === "none")
document.getElementById(id).style.display = "";
else
document.getElementById(id).style.display = "block"
}
Upvotes: 0