Monday, May 2, 2011

Remove HTML tags in a string using javascript

Hi, following code depicts how a string with HTML tags, is converted to a string without any tags.


<HTML> 
<HEAD> 
<TITLE> Remove HTML tags </TITLE> 
</HEAD> 
<BODY onload="demo();"> 
<SCRIPT LANGUAGE="JavaScript"> 
function demo()
{


var orignal= '<p align="Left"><b>I</b> <I>Rock!</I></p>'; 
var modified = orignal.replace(/(<([^>]+)>)/ig,""); 


alert(orignal);
alert(modified);



</SCRIPT> 
</BODY> 
</HTML>


Keeps Coding! :)

0 comments:

Post a Comment

 

2011 ·Code-Studio by yrus.