motomac Posted September 17, 2017 Posted September 17, 2017 Hi! I'm making a small plugin which adds buttons to every post in the topic: <li data-controller="plugins.coolAction"> <button data-action="someAction" data-name="{$comment->author_name}">Make an action</button> </li> In the coolAction.js I'm catching a click event: ;(function($, _, undefined){ "use strict"; ips.controller.register('plugins.coolAction', { initialize: function () { this.on( document, 'click', '[data-action="someAction"]', this.mention ); }, mention: function (e) { e.preventDefault(); alert($( e.currentTarget ).attr('data-name')); } }); }(jQuery, _)); But this action is invocated multiple times when I click on a button. Why?
BomAle Posted September 17, 2017 Posted September 17, 2017 try to change: this.on( document, 'click', '[data-action="someAction"]', this.mention ); with this.on( 'click', '[data-action="someAction"]', this.mention );
Recommended Posts
Archived
This topic is now archived and is closed to further replies.