Here's my code and my problem:
HTML:
<tbody id="list"></tbody>
Javascript:
let suggest;
const name = $('#post input[name=name]');
const rating = $('#post input[name=rating]');
const postinputs = $('#form-submit');
const table = document.querySelector('#list');
$.ajax({
method: 'GET',
url: wpApiSettings.root+'top-list-route/my-top-list-get',
contentType: 'application/json; charset=utf-8',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce );
},
dataType: 'json',
success: ajaxResponse
});
function ajaxResponse(data) {
let str = [];
suggest = data;
for ( let i = 0; i < suggest.length; i ++ ) {
const name = suggest[i].name;
const rating = suggest[i].rating;
str += '<tr>';
str += `<td><input type="text" value=${suggest[i].name}></td>`;
str += `<td><input type="text" value=${suggest[i].rating}></td>`;
str += `<td><button type="button">Update</button></td>`;
str += `<td><button class="delete">Delete</button><input name="delete[]" type="hidden" value=${suggest[i].id}></td>`;
str += '</tr>';
}
table.innerHTML = str;
}
Essentially I need to access the code of this string:
str += `<td><button class="delete">Delete</button><input name="delete[]" type="hidden" value=${suggest[i].id}></td>`;
In particular, I need to access the value, which is dynamically added by javascript.
I tried:
$(table).add('.delete').click( function() {
var log = $('input[name="delete[]"]').val();
console.log(log);
}
But the result is always 2, which is the first value of the array obtained from the input array of that particular element.
How can I solve my problem?
I tried also to bind the element with an event (on):
$(document).on(click, 'input[name="delete[]"]', function() {
console.log(this.val());
}
But it doesn't return anything.
frontend-rec-style.scss. scssphp will throw\ScssPhp\ScssPhp\Exception\ParserExceptionexceptions when it cannot parse the provided code.