Skip to content
Advertisement

How can I get an ID from SVG file using javascript

I’m having difficulties in accessing an ID that is inside an SVG file and inside of a rect tag, to manipulate the SVG’s I’m using the Snap.svg library. In this case I want to get the get the id="rect252" in javacript file and change the visibility of this object. For some reason I’m not able to get this ID.

My HTML:

JavaScript

My Javascript:

To place an image with Snap library

JavaScript

Function

JavaScript

SVG Structure:

JavaScript

If anyone has any suggestions I would appreciate it, thanks

Advertisement

Answer

You can’t access the id for an svg image.

However, you can if you use an object tag instead.

JavaScript

Then you can use contentDocument to access it. Example.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement