remove html tag

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

remove html tag

Post by pedroz »

How can I remove the following tag with jquery?


<p align="center">Click here <a href="http://www.domain.com/" target="_blank">My domain</a></p>

Tried

jQuery('<p align="center">Click here <a href="http://www.domain.com/" target="_blank">My domain</a></p>').replaceWith('');

but it does not work
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: remove html tag

Post by John Cartwright »

It's not clear how you are using the code you posted, but I would do something like

Code: Select all

jQuery.fn.stripTags = function() { 
   return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') ); 
};

$('#the_element_you_want_to_remove_html_from').stripTags();
Post Reply