I would like to set up a simple jQuery onClick event to make the UI dynamic on a handlebars template. I was wondering to addClass() after a specific click.
consider
there is no need to reattach the event handler on every dynamic DOM update if you're defining them at document level:
$(document).on('click','li',function(){
alert( 'success' );
});
Hope this helps! :-)
You have to refresh your Jquery listeners AFTER the insertion of nodes into your DOM HTML.
var source = "<li><a href="{{uri}}">{{label}}</a></li>";
var template = Handlebars.compile(source);
var context = {"uri":"http://example.com", "label":"my label"};
$("ul").append( template(context) );
// add your JQuery event listeners
$("li").click(function(){ alert("success"); });
I am not sure what your problem exactly is.
It's correct like this if you keep your JavaScript in a *.js file, perhaps
using parent() instead on prev()
in this specific case.