Skip to content Skip to sidebar Skip to footer

How Get Svg Code From Html Page, Using Jquery Or Javascript?

I have simple HTML page with svg like this:

Solution 1:

To combine the previous answers (which were not clear for me at first) the way to get the SVG string is following:

var str = $('<div>').append($('#plan #rect1').clone()).html(); 

Solution 2:

$('#rect1')[0]

This should help. If you want to access tag instead of jQuery element, use [] to get encapsulated element.

Edit :

This should do the trick for you.

The solution explained is to wrap your selection into another tag and call .html() on it to display its content.

Don't forget the .clone() call before appending it into your temp div, otherwise you will have some trouble in your html :)

Post a Comment for "How Get Svg Code From Html Page, Using Jquery Or Javascript?"