How to escape HTML.

Posted by kokila on Stack Overflow See other posts from Stack Overflow or by kokila
Published on 2010-06-15T08:53:00Z Indexed on 2010/06/15 9:02 UTC
Read the original article Hit count: 295

Filed under:
|
|

I have a string which contains HTML text. I need to escape just the strings and not tags. For example, I have string which contains,

<ul class="main_nav">
<li>
<a class="className1" id="idValue1" tabindex="2">Test & Sample</a>
</li>
<li>
<a class="className2" id="idValue2" tabindex="2">Test & Sample2</a>
</li>
</ul>

How to escape just the text to,

<ul class="main_nav">
<li>
<a class="className1" id="idValue1" tabindex="2">Test &amp; Sample</a>
</li>
<li>
<a class="className2" id="idValue2" tabindex="2">Test &amp; Sample2</a>
</li>
</ul>

with out modifying the tags.

Can this be handled with HTML DOM and javascript?

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html