javascript - MustacheJS: JS not working on mustache's products? -
i inject mustachejs template (button element) html. use js toggle css of buttons if clicked. js works on buttons not on created mustachejs:
function clicktogglecss() { $(this).toggleclass('status0').toggleclass('status1'); } $('button').on("click", clicktogglecss);
see this fiddle upper button true html, , bottom button injected using mustachejs.
how make work ? (fiddle appreciate!)
solution (fiddle):
$('body').on('click', 'button', clicktogglecss);
try:
$('body').on('click', 'button', clicktogglecss);
when add handler directly elements (as in code), applies elements found @ time that code ran. elements added after point not affected. using delegated handler (in case, on <body>
element), "click" event on future button handled.
Comments
Post a Comment