I have the following table having dropdown section, input field and delete button in each row. I want to get the respective row of input field when I click a delete button of a row.
$(document).on('click', '#delete-row', function() {
var value = $('this').closest('td').find('input[name="price"]').val();
alert(value);
// $(this).closest('tr').remove();
//return false;
});
<table class="table table-hover table-bordered" id="incomeId">
<thead>
<tr>
<th>
sn
</th>
<th>
Title of income
</th>
<th>
Price
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>
<select name="income-title[]" id="inputID" class="form-control">
<option value="select"> -- Select One --</option>
<option value="hostel fee"> hostel fee</option>
<option value="admission fee"> admission fee</option>
<option value="Hotel Malin -Best Hotel In the Butwal"> Hotel Malin -Best Hotel In the Butwal</option>
</select>
</td>
<td class="price">
<input type="text" name="price[]" autocomplete="off" id="income_price" class="form-control income" value="" title="" required="required">
</td>
<td>
<a href="#"><i class="fa fa-trash" id="delete-row" style="pointer:cursor;"></i></a>
</td>
</tr>
<tr>
<td>2</td>
<td>
<select name="income-title[]" id="inputID" class="form-control">
<option value="select"> -- Select One --</option>
<option value="hostel fee"> hostel fee</option>
<option value="admission fee"> admission fee</option>
<option value="Hotel Malin -Best Hotel In the Butwal"> Hotel Malin -Best Hotel In the Butwal</option>
</select>
</td>
<td class="price">
<input type="text" name="price[]" autocomplete="off" id="income_price" class="form-control income" value="" title="" required="required">
</td>
<td>
<a href="#"><i class="fa fa-trash" id="delete-row" style="pointer:cursor;"></i></a>
</td>
</tr>
<tr>
<td>3</td>
<td>
<select name="income-title[]" id="inputID" class="form-control">
<option value="select"> -- Select One --</option>
<option value="hostel fee"> hostel fee</option>
<option value="admission fee"> admission fee</option>
<option value="Hotel Malin -Best Hotel In the Butwal"> Hotel Malin -Best Hotel In the Butwal</option>
</select>
</td>
<td class="price">
<input type="text" name="price[]" autocomplete="off" id="income_price" class="form-control income" value="" title="" required="required">
</td>
<td>
<a href="#"><i class="fa fa-trash" id="delete-row" style="pointer:cursor;"></i></a>
</td>
</tr>
<tr>
<td>4</td>
<td>
<select name="income-title[]" id="inputID" class="form-control">
<option value="select"> -- Select One --</option>
<option value="hostel fee"> hostel fee</option>
<option value="admission fee"> admission fee</option>
</select>
</td>
<td class="price">
<input type="text" name="price[]" autocomplete="off" id="income_price" class="form-control income" value="" title="" required="required">
</td>
<td>
<a href="#"><i class="fa fa-trash" id="delete-row" style="pointer:cursor;"></i></a>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td>
Total:Rs
<div class="total" id="total" style="display:inline;">45</div>
</td>
<td></td>
</tr>
</tfoot>
</table>
But it gives the undefined value. Please help me to find out the answer of this problem.