JavaScript converts my < into >. I want to alert it but my message is with encoded marks like @#&*()}{>?>? – how to display it normally but prevent from executing as HTML code?
<span id="ID" onClick="alertIt(this.id);">
<p>Some string with special chars: ~!@#&*()}{>?>?>|{">@#$#^#$</p>
<p>Why when clicked it gives something like this:</p>
<p>'<br>
Some string with special chars: ~!@#&*()}{>?>?>|... and so on
<br>'</p>
</span>
<script type="text/javascript">
function alertIt(ID)
{
var ID = ID;
var content = document.getElementById(ID).innerHTML;
alert(content);
}
</script>
Use
innerTextinstead ofinnerHTML. http://jsfiddle.net/WVf95/