Я работаю над простым менеджером списков для изучения PHP с помощью jQuery.Я не смог передать значение элемента to to сценарию.В результате я не могу удалить элементы.
Я новичок в jQuery, но попробовал Google :), чтобы найти решения.К сожалению, не удалось.
html-анализ через скрипт
tasks.forEach(task => {
template += `
<tr>
<td>${task.id}</td>
<td>
<a href="#" class="task-item">
${task.name}
</a>
</td>
<td>${task.description}</td>
<td>
<button value="${task.id}" class="task-delete btn btn-danger">
Delete
</button>
</td>
</tr>
`
});
//script with the delete function
$(document).on('click', '.task-delete', (e) => {
console.log('FetchTaskCheckDelete1!');
if(confirm('Are you sure you want to delete it?')) {
const element = $(this)[0].activeElement.parentElement;
var element2 = $(this).attr("value");
const id = $(element).attr("id");
console.log('FetchTaskCheckDelete2!');
console.log(element);
console.log(element2);
console.log(id);
$.post('task-delete.php', {id}, (response) => {
fetchTasks();
});
}
});