Javascript Detects InnerText and Strips HTML Tags

[Total: 0    Average: 0/5]

This code will strip out all HTML tags from a given HTML element.

Head Code:

<script>
function ex_init()
{
  var temp="";
  var regExp=/<S[^>]*>/g;
  var _obj=document.getElementById("me");
  temp=document.f1.t1.value=_obj.innerHTML;
  document.f1.t2.value=temp.replace(regExp,"");
}
</script>

Init Code:

ex_init();

Body Code:

<h1 id="me"><b>Hi<i> There</i></b></h1>
<hr>
<form name=f1>
InnerHTML:<textarea name=t1></textarea><BR>
Replaced:<textarea name=t2></textarea><BR>
</form>

Times Viewed: 9

Leave a Reply

Your email address will not be published. Required fields are marked *