I am using jQuery, and have an HTML block as follows:
<div id="html-block">
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
</div>
Which renders as:
Heading 1
Heading 2
Heading 3
What I am trying to do is show what HTML was used to create this block.
If I use $(this).clone().insertAfter(this); simply repeats what we see rendered, but what I actually want to see in my browser is:
<div id="html-block">
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
</div>
What's the best way to do this?
document.getElementById('html-block').outerHTMLtext, which will HTML-encode the passed value:$('<div/>', { text: $(this).html() }).insertAfter(this);. Can also be called as a functioncontainer.text( ... ).append()?