Reputation: 3025
So, I've got a widget that is looking to output live HTML source as text, as part of a review process. Is there a way that I can take a selected element, append it to a target div, and have it output as text instead of as a child in the DOM?
UPDATE: I'd like to avoid textareas if possible - they present a complication in my form setup, as well as a vulnerability for anyone with basic skill in firebug/inspectEl.
Upvotes: 0
Views: 1930
Reputation: 3390
If you want to avoid textarea
then the only other possible option I know is of <code>
tag and <pre>
tag will recognize white spaces so that code is properly indented. Try this fiddle.
Upvotes: 1
Reputation: 905
You need to escape the html characters, so < becomes < etc. - see answers here: Escaping HTML strings with jQuery
Upvotes: 2
Reputation: 3523
You could insert the code into a textarea tag and the html will be printed as text
jQuery('#idOfTextArea').text(html);
Upvotes: 2