jquery - Dynamic class for Meteor Event Map -
i trying create wizard package , can't seem able setup click event on element.
i want person using package able define next , previous buttons class values , apply event when element classes clicked.
it works fine when use static class values if try use ones define when initialize wizard fails unexpected token value. have tried printing classes console within events function , printing out fine.
this works fine uses static class name
template.wizard.events({ "click .btn-prev": function (event) { event.preventdefault(); this.wizard.previous(); } });
this won't work unexpected token +
error
template.wizard.events({ "click ." + this.wizard.prevclass: function (event) { event.preventdefault(); this.wizard.prev(); } });
i tried around doing if statement seems return false.
template.wizard.events({ 'click': function (event) { event.preventdefault(); if ($(this).hasclass(this.wizard.nextclass)){ this.wizard.next(); } } });
what supposed $(this)
? in callback of click :)
if want find after click, should try event current target (not target, different), or second argument of click (the template) :
template.wizard.events({ 'click': function (e, tmpl) { event.preventdefault(); console.log(e.currenttarget); console.log(tmpl); console.log(tmpl.find(this.wizard.nextclass); if( e.currenttarget.classname === this.wizard.nextclass ) this.wizard.next(); } });
Comments
Post a Comment