javascript - How to replace < and > with &lt; and &gt; with jQuery or JS -


i've been searching day or how js or jquery , found couple of solutions nothing solid yet.

i want use this:

<code class="codeit">    <h2> h2 </h2>  </code> 

and want output be:

<h2> h2 </h2>

i know can achieve doing:

<code class="codeit">    &lt;h2&gt; h2 &lt;/h2&gt;  </code> 

...but not manual search , replace on code in blocks , rather have done on fly in browser. possible?

i'm pretty noob jquery i've tried .replacewith or javascript's .replace far i've not gotten need it. i'm either replacing whole tag or doing else wrong.

my question is: how write simple jquery (or regular js) me replace < , > html entities &lt; , &gt; inside <code> tags.

i appreciate help, thanks.

update:

i managed working nice how @prisoner explained, it's nifty, in particular case needed little extending because have more 1 block of code .codeit class, had make check each element , output... otherwise keep making same output (like first block)

here fiddle

thanks answers.

assuming want escape html:

$(".codeit").text($(".codeit").html()); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -