I have a table and for this table i have an icon "plus" and for each row i have an icon "edit".
When i press "plus" it will create another tr with a select in it and an icon "edit".
This "edit" has an id that is equal with the number of the row,so the first "edit" icon will have id=1,the second id=2 and so on(i'm using an i++ for this).
My problem is that,when i press on "edit" icon i want to display in console the id of the icon(testing porpouse),but this will only work on the first icon.
I saw in another question that this will happen if you have the same id on more elements,but i don't.The code is this:
The main table,with just one row:
<table id="dynamic">
<tr id="row1">
<td>
<select class="form-control select-table" name="products[]" id="select-1" data-dep="">
<?php foreach($products as $product):?>
<option value="<?php echo $product['products_id'];?>"><?php echo $product['product_name'];?></option>
<?php endforeach;?>
</select>
<i id="1" data-toggle="modal" data-target="#editModal" class="fas fa-edit fa-lg edit-div"></i>
<div id="plus-div"><span><i class="fas fa-plus fa-lg"></i></span></div>
</td>
</tr>
</table>
The jquery code where i add a new row:
var i = 1;
$('#plus-div').click(function(){
i++;
j++;
$('#dynamic').append('<tr id="row'+i+'"><td><select id="select-'+i+'" class="form-control select-table" name="products[]">' +
<?php foreach ($products as $product):?>'<option value="<?php echo $product['products_id'];?>"><?php echo $product['product_name'];?></option>' +
<?php endforeach; ?>
'</select><i id="' + i + '" data-toggle="modal" data-target="#editModal" class="fas fa-edit fa-lg edit-div"></i></td></tr>');
});
The jquery code where i display the id:
$('.edit-div').click(function(){
console.log((this).id);
});