I am having an issue very similar to: \"Jquery \'click\' not firing when icon is on button\" however the resolution for that post is not providing a solution for me, so I th
update this because $(event.target) is not always button for this you have to use ternary operator as suggested or replace $(event.target) with $(this) which is always button in the context of selector:
function sendVote(event) {
event.stopPropagation();
var $btn = $(event.target).is('button') ? $(event.target) : $(event.target).parent();
console.log(parseInt($btn.data('vote')));
console.log($btn.prop('tagName'));
}
$(function () {
$('body').on('click','button.vote-button', sendVote);
});
or with $(this) which is always button because the event is bound to it and if you click on any child of it then event will bubble up to the dom tree and event bound to button gets executed:
function sendVote(event) {
var $btn = $(this); // <-----------------change just here
console.log(parseInt($btn.data('vote')));
console.log($btn.prop('tagName'));
}