Hi I have a Table with list of vehicle
<table>
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}" id ="rows">
<td>
<div class="check_box_div">
<div class="check_box_list">
<g:checkBox id = "isActive_${i}" class="isActive" name="isActive" value="${vehicleInstance?.isActive}" />
<input type="hidden" value="${vehicleInstance?.id}" class="vehicleId" name="vehicleId" id="isActive_${i}_" />
</div>
<div class="display_image" id ="display_image_${i}"></div>
</div>
</td>
</tr>
table has got many rows
I want to get the id of div where the class name is “display_image” for each row i tried to get it like
$(".isActive").click(function() {
var checkBox_id = $(this).attr("id");
var checkbox = $('#'+checkBox_id);
var div_id =$('#'+checkBox_id).closest("div").find(".display_image").attr("id"); // always returns div_id =display_image_0(div id of first row)
This is works for first row but for second row also it returns id of div of first row only
what is the change i should make so that i will get the id of div on each row
Go up until you find the row, and then down again to find the display image:
Note that this doesn’t depend on your original element’s ID at all – just the layout of your elements within the DOM.
More optimal solutions are possible, but this one will work regardless of the relative positions of the
.isActiveand.display_imageelements within each row.