Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the elements and contents before an element

Tags:

jquery

forms

I am trying to remove the elements and contents before a link inside a div when a user clicks a button. What is the best way to do it??

<div id="dialog" class="window">  

         //will be inserted a <select> element and few text here 
         //but I want to clear them after the user click a button

    <a href="#" class="close">Close it</a>  // I want to keep this <a> link.    

    </div>  

My Jquery

$('.model').click(function(e) {  

   $("#dialog").empty();  //I can't use this because <a> will be deleted. Any better ideas?         

});

Thanks for the reply...

like image 701
FlyingCat Avatar asked Feb 07 '26 02:02

FlyingCat


1 Answers

Just wrap all those elements in a div and remove them

$('#select-wrapper').remove();

or do it a little more friendlier

$('#select-wrapper').fadeOut(500, function() { $(this).remove(); });
like image 144
alex Avatar answered Feb 09 '26 09:02

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!