0

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!

supersize
  • 13,764
  • 18
  • 74
  • 133
  • possible duplicate of [jQuery, get html of a whole element](http://stackoverflow.com/questions/3614212/jquery-get-html-of-a-whole-element) – isherwood Apr 08 '14 at 23:10
  • @isherwood I don't think so, because I just want the HTML of a specific element, not the outer HTML and the content. – supersize Apr 09 '14 at 01:47

1 Answers1

2

I'd suggest:

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

Simplified proof of concept.

David Thomas
  • 249,100
  • 51
  • 377
  • 410