supersize
supersize

Reputation: 14773

take only specific element out of content with .html()

I would like to get the .html() of an iFrame. But I only want the code of an specific element <img id="picture">. How can I get the HTML but have only the <img id="picture"> with all parameters.

Something like:

$('#mydiv').find("iframe").contents().find("body").html(/*only get html of image here*/);

Thank you!

Upvotes: 0

Views: 59

Answers (1)

David Thomas
David Thomas

Reputation: 253318

I'd suggest:

var imgEl = $('#mydiv iframe #picture'),
    imgHTML = imgEl.prop('outerHTML');

Simplified proof of concept.

Upvotes: 2

Related Questions