I have an HTML code as shown below. I have copied this from DOM and it is generated through php.
<div class="house-senate-committee" style="text-align:center; margin-top:15px;">
<button type="button" onclick="removeRow()" name="delete_row[]" style="margin-right:10px;" value="">Delete</button>
<input type="text" name="code[]" style="margin-right:10px;" value="AEFA">
<input type="text" name="en_desc[]" value="Foreign Affairs and International Trade">
</div>
<div class="house-senate-committee" style="text-align:center; margin-top:15px;">
<button type="button" onclick="removeRow()" name="delete_row[]" style="margin-right:10px;" value="">Delete</button>
<input type="text" name="code[]" style="margin-right:10px;" value="AGFO">
<input type="text" name="en_desc[]" value="Agriculture and Forestry">
</div>
The above HTML code belongs to the following screenshot:
Problem Statement:
I am wondering what JS code I need to add so that on clicking Delete button it deletes a row containing that button.
For example: If I click the 2nd row Delete button, it should delete the complete 2nd row and if I click the 1st row Delete button, it should delete the complete 1st row.
This is what I have tried:
function removeRow() {
document.queryselector(".house-senate-committee").remove();
}