Die 20
Die 20

Reputation: 261

deleting the parent div using jquery

I have a jquery scripts aimed at deleting the parent div. However, the delete button doesn't appear as a button and won't delete the parent div. I am using jQuery Mobile.

Here is the jquery:

 $(".delete_content").click(function() { 
    $(this).closest(".content_container").remove();   
   });

Here is the html:

<div class='content_container'>
      <a class='delete_content' data-role='button' data-icon='delete' data-inline='true' data-iconpos='right'>
            Delete
      </a>
</div>

Upvotes: 0

Views: 61

Answers (1)

Naftali
Naftali

Reputation: 146310

$(".delete_content").click(function() { 
    $(this).parents(".content_container").remove();   
});

You need to use .parents and not .closest

Upvotes: 3

Related Questions