handling jQuery onClick event on handlebars

前端 未结 3 1918
花落未央
花落未央 2020-12-31 06:18

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

3条回答
  •  猫巷女王i
    2020-12-31 07:07

    You have to refresh your Jquery listeners AFTER the insertion of nodes into your DOM HTML.

    var source   = "
  • {{label}}
  • "; 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"); });

提交回复
热议问题