javascript - How can I display HTML tags as Text using jQuery? -
javascript - How can I display HTML tags as Text using jQuery? -
i trying display unrendered html code using class html
, below jquery code. working every tag except tags <html>
, <head>
, <body>
. there way these can displayed text?
$(document).ready(function () { $('.html').each(function () { $(this).text($(this).html()); }); });
html code:
<pre> <div class="html"> <html> <head><title>title</title></head> <body> <p>unrendred html</p> </body> </html> </div> </pre>
expected content:
<div class="html"> <html> <head><title>title</title></head> <body> <p>unrendred html</p> </body> </html> </div>
actual content:
<title>title</title> <p>unrendred html</p>
your html invalid. can't have of tags putting them.
when browser tries parse invalid html, hits errors , attempts recover them.
the result of never set within .html
element in dom, when seek convert dom html won't appear.
the way scrape them out of there refetch raw source code server , parse html yourself.
just write html correctly in first place. if want render <
character set <
in html (and on). don't seek escape html javascript after browser has parsed it.
javascript jquery html html5 dom
Comments
Post a Comment