Shai UI
Shai UI

Reputation: 51918

How to get the svg element from inside an embed tag?

<embed id='mysvg' src='mysvg.svg' onload='myFunc(this)'/>

This loads an external svg file. Now inside myFunc I'd like to get a reference to the actual svg tag. Meaning, there's an <svg> inside this file, and I'd like to set an attribute on this svg tag from javascript. But how do I get a reference to it?

I tried:

function myFunc(elem)
{
    $(elem).find('svg').attr('preserveAspectRatio','none'); // doesn't work
}

Upvotes: 3

Views: 1272

Answers (1)

Robert Longson
Robert Longson

Reputation: 124016

Something like this perhaps...

var svg = $(elem.getSVGDocument().documentElement);

svg.attr('preserveAspectRatio','none');

documentElement returns the root element of a document so you don't need to 'find' it.

Upvotes: 2

Related Questions