A perfect code references for developers


Jquery closest function with example


Using the jquery closest method to look for the parent element and remove the entire row.

Demo

  • By clicking on remove button its respective row will be removed from the html table.
NameAddressPhoneEmailRemove
KevinAddress One +11111111111 email1@email.com
MarkAddress Two +2222222222 email2@email.com
HectorAddress Three +3333333333 email3@email.com

Input button with the selector class remove check for its closest parent class tblrow to remove the entire row from the html table.


$(document).ready(function(){
	$(".remove").click(function(){
		$(this).closest('.tblrow').remove();
	});
});

HTML Table


Name Address Phone Email Remove
Kevin Address One +11111111111 email1@email.com
Mark Address Two +2222222222 email2@email.com
Hector Address Three +3333333333 email3@email.com