Page 1 of 1

remove html tag

Posted: Mon Mar 14, 2011 2:14 pm
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

Re: remove html tag

Posted: Mon Mar 14, 2011 4:21 pm
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();