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
remove html tag
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: remove html tag
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();