Dipendra Km Dipendra Km - 6 months ago 21
jQuery Question

Can we remove the div having the id inside the div class using jquery

<div class="row">
<div id ="1">Here is content</div>
<div id ="2">Here is content</div>
<div id ="3">Here is content</div>
</div>
<button id ="remove">


I want to remove the row form last(3 ,2 ,1) on clicking button using j query please suggest me a code.

Answer

When you click remove button ,get the class row and you want to delete its children so use children() .Can remove last index by last() function and remove().

$('#remove').click(function() {
  $('.row').children().last().remove();
})