0

I have a page which contain dynamic content.

<div id="content-1">
    <div id="subcontent-1"></div>
    <i id="delete-1"></i>
</div>
.
.
.
<div id="content-10">
    <div id="subcontent-10"></div>
    <i id="delete-10"></i>
</div>

How to select dynamic content with jQuery selectors and how to understand which content will be deleted I'm not sure and confused.

Need to understand which delete for clicked by user.

Tushar
  • 85,780
  • 21
  • 159
  • 179
Mehmet
  • 3,301
  • 8
  • 26
  • 36

1 Answers1

1

In your markup, it will be easier to select elements if you can add a class to them like

<div id="content-1" class="content">
    <div id="subcontent-1"></div>
    <i id="delete-1" class="delete">i</i>
</div>

then use the class selector to register the event handlers

$(document).on('click', '.content .delete', function(){
    $(this).closest('.content').remove();
})
Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531