So I’m iterating through a list of returned elements in a jQuery .each() call and what I want to do is return a string that has the contents AND tag of the element in question. For example:
<div class="foo">
<div class="bar">Blah blah</div>
<div class="bar">Blah blah</div>
</div>
If I ran a $('.bar').each(function()) I want it to return
'<div class="bar">Blah blah</div>'
This uses the browser’s
outerHTMLproperty if it is available, otherwise it creates a new<div>, makes a clone of the element, places it inside, and get’s the.html()of the<div>.