0

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:

$('<div></div>')

I need just the html so '<div></div>'

Thanks!

User123
  • 549
  • 1
  • 11
  • 24

1 Answers1

3

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>";
freedomn-m
  • 27,664
  • 8
  • 35
  • 57
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964