Click event on button is sending an icon as the target?

前端 未结 5 1470
走了就别回头了
走了就别回头了 2020-12-24 07:17

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

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 08:05

    How bout just checking within the function if the tagname is I, and if it is, getting the parent as your $btn. http://jsfiddle.net/jFIT/qZgYU/3/

    $('body').on('click', 'button.vote-button', function() {
     var $btn = $(this).prop('tagName').toLowerCase() == "i" ? $(this).parent() : $(this);
     console.log(parseInt($btn.data('vote')));
     console.log($btn.prop('tagName'));
    });
    

提交回复
热议问题