how to remove html tags in javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
renu
Forum Commoner
Posts: 30
Joined: Sat Nov 06, 2004 12:20 am

how to remove html tags in javascript

Post by renu »

Hi

Can anyone tell how to remove html tags from a string in javascript.

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

viewtopic.php?t=25494

the regex used later in the thread (sorry about the formatting) can be used to correctly remove all tags.
renu
Forum Commoner
Posts: 30
Joined: Sat Nov 06, 2004 12:20 am

Post by renu »

hey but this is php code.i want to to use that in javascript.
Actually i have a string in javascript having html tags.i want to remove them before form submitting.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the regular expression in that thread can be transferred into javascript fairly easily.
renu
Forum Commoner
Posts: 30
Joined: Sat Nov 06, 2004 12:20 am

Post by renu »

can u tell how to use that.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

var matches = Somestring.match(/regexp(In)Here/)
Parentheses around the parts of the expression you wish to extract
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

or even (after reading that thread) you need to do a search and replace as follows....

Code: Select all

var newstring = oldString.replace(/yourRegexp/, 'YourReplacement')
Just copy the regExp and replacement from the other thread and it'll work ;-)

EDIT: Here..

Code: Select all

var newString = taggedString.replace(/#<.*?(\s+&#1111;\w\W]+?(\s*=\s*(&#1111;''"]?).*?\\3))*?>#s/, '')
Post Reply