tenants
Well-known member
If I create content dynamically, how can I re-add a class listener
For instance, if my page has
And my external script uses
Then the click event is bound to all links on that page with the class "SomeClass" .... that works all well and good.
But if I now dynamically add <a class="SomeClass">click me2</a> so that my page is now:
The binding will only occur on the first link (the link that is not dynamically created) and not the second. How can I re bind my class event listener on content that is created dynamically (or all content)?
(I think this is a scope issue)
For instance, if my page has
Code:
<a class="SomeClass">click me</a>
<div>more</div>
And my external script uses
Code:
!function($, window, document, _undefined) {
XenForo.SomeClass = function($lnk){
$lnk.bind('click', function() {
doSomething();
return false;
});
}
XenForo.register('a.SomeClass', 'XenForo.SomeClass');
}(jQuery, this, document);
Then the click event is bound to all links on that page with the class "SomeClass" .... that works all well and good.
But if I now dynamically add <a class="SomeClass">click me2</a> so that my page is now:
Code:
<a class="SomeClass">click me</a>
<div>more</div>
<a class="SomeClass">click me2</a>
The binding will only occur on the first link (the link that is not dynamically created) and not the second. How can I re bind my class event listener on content that is created dynamically (or all content)?
(I think this is a scope issue)