JS replace class on click
имею следующую структуру
<td><a href="#" id="123" class="file_not_find">
<i class="fa fa-times" style="font-size:24px"></I>
</a>
</td>
Забираю ID по нажатию на ячейки, просьба, подсказать, как дополнительно корректно заменить class в данном случае, пытаюсь следующим скриптом
$('#table tbody').on('click', '.file_not_find', function(){
var id = $(this).closest('.file_not_find').attr('id');
$(this).closest('.fa fa-times').removeClass('.fa fa-times');
$(this).addClass('fa fa-spinner fa-pulse');
console.log(id)
$.ajax({
url: '/dwnld',
type: 'post',
data: {name_file: id}
})
})
Ответы (1 шт):
Автор решения: Pavel Nazarian
→ Ссылка
$('#table tbody .file_not_find').click(function(){
let id = $(this).attr('id');
$(this).find('i').removeClass('fa-times');
$(this).find('i').addClass('fa-spinner fa-pulse');
console.log(id)
$.ajax({
url: '/dwnld',
type: 'post',
data: {name_file: id}
})
})