admin管理员组文章数量:1334342
I simply need to define a click event for this HTML:
<button data-method="rotate" class="btn btn-default">
<i class="fa fa-rotate-left"></i>
</button>
html
Template.page.events({
'click button': function (event) {
var $button = $(event.target),
method = $button.attr('data-method');
}
});
But now there is the problem, that this only works if the user doesn't click on the fa icon, because then the event target is different. In this case method
will be undefined.
How can I prevent this?
I simply need to define a click event for this HTML:
<button data-method="rotate" class="btn btn-default">
<i class="fa fa-rotate-left"></i>
</button>
html
Template.page.events({
'click button': function (event) {
var $button = $(event.target),
method = $button.attr('data-method');
}
});
But now there is the problem, that this only works if the user doesn't click on the fa icon, because then the event target is different. In this case method
will be undefined.
How can I prevent this?
1 Answer
Reset to default 8Why not just
$(this) // or $(e.currentTarget)
instead of
$(event.target)
event.target
points you to the actual element that triggers your event.
But in your case you want that to be a button and all its descendent elements.
本文标签: javascriptJS event target for button with iconStack Overflow
版权声明:本文标题:javascript - JS: event target for button with icon - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742368204a2461715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论