Franco Franco - 1 year ago 53
HTML Question

Add element to document and then remove it using Jquery

I am adding text to an element in Jquery using

$('.alert-saved').append('<br /><a href="/?similar=' + release_id + '&source=index">See more like this >></a>')

I then show this to the user and pause.


I would now like to remove all the text I appended.

I have tried this but it didn't work

$('.alert-saved').remove('<br /><a href="/?similar=' + release_id + '&source=index">See more like this >></a>')

Answer Source

Just pass an empty HTML string argument:



If you need to keep other elements, you can use this method:

var newLine = jQuery('<br /><a href="#your whatever">See more like this</a>');
setTimeout(function() {
}, 2000)
<script src=""></script>
<p class="alert-saved">
  <span>I wanna stay!</span>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download