0

I have this html code:

<div class="action">
   some_text
   <a class="delete_action" name="q1">some</a>
</div>
<div class="action">
   some_text
   <a class="delete_action" name="q2">some</a>
</div>

And jQuery code:

$(document).ready( function() {
   $('.delete_action').click(function(event) {
       $.get('/delete_action?name=' + event.target.name, function(data) {
       });

       // how can I remove parent DIV element (*)

       return false;
    });
} );

When the user click the link, the code makes ajax-request which removes the data in the database. In addition I want to remove parent DIV element from DOM tree. How can I get it?

3692
  • 628
  • 2
  • 6
  • 17
ceth
  • 44,198
  • 62
  • 180
  • 289

2 Answers2

2

you would use

$(document).ready( function() {
   $('.delete_action').click(function(event) {
       var $this = $(this);
       $.get('/delete_action?name=' + event.target.name, function(data) {
            $this.parent().remove();
       });

       // OR
       //$this.parent().remove();

       return false;
    });
} );
Kim Tranjan
  • 4,521
  • 3
  • 39
  • 38
1

Try:

$('.delete_action').click(function(event) {
   $.get('/delete_action?name=' + event.target.name, function(data) {});
   $(this).parent().remove();
   return false;
});
David Hellsing
  • 106,495
  • 44
  • 176
  • 212