Answer the question
In order to leave comments, you need to log in
How to get href of jQuery link?
I'm trying to access the href attribute of a link with the remove class , I get
links to remove objects myself with Ajax
, here's my code
function renderCand (data) {
$("a#countCandidates > span.badge").text(data.length);
$("#listCandidates").empty();
data.forEach(function(item){
$("#listCandidates").append('<tr>'+
'<td>'+item.id+'</td>'+
'<td>'+item.name+'</td>'+
'<td>'+
'<a href="#" class="thumbnail">'+
'<img src="http://placehold.it/140x100" alt="...">'+
'</a>'+
'</td>'+
'<td>'+item.description+'</td>'+
'<td>'+
'<div class="btn-group" role="group" aria-label="...">'+
'<a href="'+Routing.generate("candidates_delete",{id: item.id})+'" class="btn btn-xs btn-danger remove"><i class="fa fa-trash-o"></i></a>'+
'<a href="#" class="btn btn-xs btn-warning"><i class="fa fa-edit"></i></a>'+
'</div>'+
'</td>'+
'</tr>');
});
}
$(".remove").bind('click',function(event){
event.preventDefault();
alert($(this).attr('href'));
return false;
});
Answer the question
In order to leave comments, you need to log in
$(".remove").bind('click',function(e){ // bind лучше заменить on
e.preventDefault(); // Отменяет стандартное действие ссылки
alert($(this).attr('href'));
return false; // Не совсем понял, зачем вы возвращаете что-то из колбека. Это можно убрать
});
$(".remove").on 'click', (e)->
e.preventDefault()
alert $(this).attr 'href'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question