I want to select a certain element inside an array in jquery, getting the class which is something like . My purpose is to edit each row and then changing them dynamically with Ajax. The first step is to select all of each row with jquery onclick.
My code is the following:
<?php foreach ($database as $item): ?>
<tr class="row_<?php echo $item["id"]; ?>">
<th id="id_<?php echo $item["id"]; ?>"><?php echo $item["id"]; ?></th>
<th contentEditable="true" class="credit_type"><?php echo $item["credit_type"]; ?></th>
<th contentEditable="true" class="association_name"><?php echo $item["association_name"]; ?></th>
<th contentEditable="true" class="address"><?php echo $item["address"]; ?></th>
and so on which is producing the following html:
<tr class="row_1 odd">
<th id="id_1">1</th>
<th contenteditable="true" class="credit_type">0</th>
<th contenteditable="true" class="association_name">ciao</th>
<th contenteditable="true" class="address">123 cool street</th>
<th contenteditable="true" class="city">Toronto</th>
<th contenteditable="true" class="province">0</th>
<th contenteditable="true" class="postal_code">l4n4m4</th>
<th contenteditable="true" class="country">0</th>
<th contenteditable="true" class="cycle_type">0</th>
<th contenteditable="true" class="cycle_begin">2018</th>
<th contenteditable="true" class="cycle_months">1</th>
<th><button class="edit" id="edit_1">Edit</button></th>
<th><button class="edit" id="delete_1">Delete</button></th>
</tr>
With jquery, I want to select all the children element of the column with the class of row_1 and do it for each row (row_2, row_3 and so on).
My jquery is pretty basic:
$(document).ready(function(){
$( "button.edit" ).click(function() {
var id = this.id;
var value = $(".row_ th").text();
}
$.ajax({
url: 'update.php',
type: 'post',
data: { all_my_value },
success:function(response){
console.log('Save successfully');
}
});
My question is that if there is any way to add my dynamic value id to the row when I get all the elements with a certain class.