I want to get the whole HTML tag of an image (<img src="url" ... />
). I can do it with .html()
function if I refer to its parent:
<div id="image">
<img src="url" />
</div>
and with JQuery:
$('#image').html()
But how could I do it if I don't have an image "only" parent:
<div id="image">
<img src="url" />
<!-- Here some stuff. E.g. -->
<div><p>Something</p></div>
</div>
If I do $('#image').html()
here, I'll get the whole content. If I do $('#image img').html()
I'll get an empty string.
How could I get the whole <img>
tag here?