0
var div = $('<div/>').text('inner text');

I want the full html of the div element including the element itself, not just the text inside it.

How can I do that?

div.get(0) // gives me an HTML Element Object, which I'm not sure what to do with.
Nicekiwi
  • 4,567
  • 11
  • 49
  • 88

1 Answers1

5

get(0) will give you an object, use outerHTML property on it.

div.get(0).outerHTML

or

div.prop('outerHTML')

var div = $('<div/>').text('inner text');
alert(div.get(0).outerHTML)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Shaunak D
  • 20,588
  • 10
  • 46
  • 79