User123 User123 - 8 months ago 42
jQuery Question

How to get raw html passed as jQuery selector?

Note: Answer given by SLacks requires the least code to get what I want compared to answers in the duplicate questions. Accepting this.

I'm trying to do get the raw html that's passed in as the selector:


I need just the html so



You're looking for the native outerHTML property: el[0].outerHTML

Note: this is not quite "raw"; this is the HTML as parsed by the browser.

example of parsed output:

$("<div></div>")[0].outerHTML = "<div></div>";    
$("<div/>")[0].outerHTML = "<div></div>";