I am using Select2 Multiple Selection
Clicking on x I want ID of table row.
This is a code snippet to see the real problem. https://jsfiddle.net/ja1omn9x/
I am using this code:
But it's giving me undefined
What should be the way?
$(document).on('click', '.select2-selection__choice__remove', function(e) {
console.log("YES: ", $(this).closest('tr').attr('id'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<tr id="row1">
<td data-select2-id="4">
<select name="product_id[]" class="invoiceProducts">
<option value="12" data-select2-id="19">Orange</option>
<option value="14" data-select2-id="20">Apple</option>
</select>
<span class="select2>
<span class=" selection ">
<span class="select2-selection select2-selection--multiple ">
<ul class="select2-selection__rendered ">
<li class="select2-selection__choice " title="Apple " data-select2-id="23 ">
<span class="select2-selection__choice__remove " role="presentation ">×</span>Apple</li>
</ul>
</span>
</span>
<span class="dropdown-wrapper " aria-hidden="true ">
</span>
</span>
</td>
</tr>
