Strip Tags (jQuery/Javascript)
By | Wednesday, January 11, 2012


Hide Comments






jQuery:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function strip_tags(str){
t = str.replace(/<(/)?(html|head|title|body|h1|h2|h3|h4|h5|h6|p|br|hr|pre|em|strong|code|b|i|a|ul|li|ol|dl|dd|table|tr|th|td)([^>]*)>/gi, "");
t = t.replace(/<(/)?(iframe|frameset|form|input|select|option|textarea|blackquote|address|object)([^>]*)>/gi, "");

$("#t").html(t);
}
</script>
</head>
<body>
<textarea onKeyUp="strip_tags(this.value)"></textarea>
<span id="t"></span>
</body>
</html>
Javascript:
<html>
<head>
<script>
function strip_tags(str){
t = str.replace(/<(/)?(html|head|title|body|h1|h2|h3|h4|h5|h6|p|br|hr|pre|em|strong|code|b|i|a|ul|li|ol|dl|dd|table|tr|th|td)([^>]*)>/gi, "");
t = t.replace(/<(/)?(iframe|frameset|form|input|select|option|textarea|blackquote|address|object)([^>]*)>/gi, "");

document.getElementById("#t").innerHTML = t;
}
</script>
</head>
<body>
<textarea onKeyUp="strip_tags(this.value)"></textarea>
<span id="t"></span>
</body>
</html>