Rasmus Vind
Well-known member
I was under the impression that XenForo.register(selector, fn) would run fn every time an object matching selector would appear. I wrote a little sample of how I thought it would work:
I have this in my template:
So I was expecting "The button" to be clickable each time but apparently it only works the first time. I do get something like this in the console:
This is just some sample code. I have some HTML that I replace each time the user does a certain action with it and I don't want to manually re-bind events. I thought that was the point of XenForo.register, that it works with elements created at a later point using XenForo.activate.
Code:
XenForo.MyButton = function($ele) {
return $ele.bind('click', function() {
var $template;
$template = $($ele[0].outerHTML);
return $template.xfInsert('replaceAll', $ele, 'slideDown', XenForo.speed.fast);
});
};
I have this in my template:
Code:
<div class="MyButton">The button</div>
So I was expecting "The button" to be clickable each time but apparently it only works the first time. I do get something like this in the console:
Code:
XenForo.activate([div.MyButton.__XenForoActivator, prevObject: e.fn.init[1], context: undefined, jquery: "1.11.0", constructor: function,selector: ""…]
This is just some sample code. I have some HTML that I replace each time the user does a certain action with it and I don't want to manually re-bind events. I thought that was the point of XenForo.register, that it works with elements created at a later point using XenForo.activate.
Last edited: