When using a foreach from jTemplate, jQuery doesn't hook into the .click()
event of any DOM Elements within the applied template.
Solutions such as .live('click', function())
do not work (Partially because .live was deprecated, but the alternative introduced to replace it .on('click', function())
does the same thing...), and i cannot figure out how to get Click events from the results of a jTemplate.
Thing's i've tried:
.live('click', function())
.click(function())
.on('click', function())
$(window).load(function())
, $(document).ready(function())
, and just freely in a Script tag.processTemplate()
functionAt this point, i have no more ideas on how to solve this issue.
My jQuery version for reference is 2.1.3, and jTemplate is 0.8.4.
As for jQuery 1.7 and above, to delegate event, you should use on() method and passing selector parameter.
Here is an example, even it is usally better to bind it to closest static container, not the document
:
$(document).on('click', 'selector', handler);
You can as a good read see following link: http://learn.jquery.com/events/event-delegation/