blueimp/JavaScript-Templates

jQuery Events

Closed this issue · 1 comments

Hello,

I'm working on a project that uses the upload script with the template script (tmpl).

However, when the tmpl() creates an element based on a template within a <script></ script>, the element receives no event previously assigned of jQuery.
I know this is natural, but I wonder if there is anything that can be done.

I thought of a solution:

  • If the template can be passed in the form of element jQuery $(elem), this may have come with the assigned events. I know the tmpl() runs without jQuery, but a validation could help.

This template library here is String-based, that means the HTML code to create the actual DOM elements is just a String, which naturally doesn't pass along any events.
So my advice would be to listen to events on the parent element where you insert the template and then use a selector to differ between the actual events, e.g.:

$('#example-parent-element').on('click', '.start', function (e) {
    // event handler code
});

See also http://api.jquery.com/on/#on-events-selector-data-handlereventObject