javascript - MeteorJS - event click after template.onRendered -


i've got template want add click event meteor.template.event(). problem .event() not working right , can't hold of dom.

im using meteor.template.onrendered() display api data , i'm using jquery shove data template. want grab [name] selector generated through jquery , manipulate meteor.template.event() it's not working

//server meteor.method() incrementnormalpoints: function(err){   points.upsert( {userid: this.userid}, { $inc : {normalpoints : 2} }); }  //client meteor.template.onrendered().. part works  template.normalmode.onrendered(function(){   $("[name=imageguess").append('<div class="flip"><div name="imagecard" class="card"><div class="face front"><img name="rightanswer" id="theimg" class="img-responsive" src="'+imgarray[i]+'" /></div><div class="face back"><span class="center-glyphicon glyphicon glyphicon-ok"></div></div></div>'); }  template.normalmode.events({   "click [name=rightanswer]" : function(){      event.preventdefault();      meteor.call("incrementnormalpoints");      console.log("hello");   } }); 

hope made sense. @ moment console log in events() function isn't working either. i'm pretty sure it's because of dom not "existing" , js can't hold of it.

alright found workaround problem , works. want @ moment. overlooked meteor.events() , worked through meteor.onrendered() block.

i made function upsertnpoints() "calls" declared method on server , uses upsert points points table.

//server methods() incrementnormalpoints: function(err){ points.upsert( {userid: this.userid}, { $inc : {normalpoints : 2} }); if(err){   console.log(err); } },  //upsert database using call() method meteor provides on client function upsertnpoints(){   $("[name=rightanswer]").on("click", function(){     meteor.call("incrementnormalpoints");     location.reload(true);//this reload window after click   }); }  upsertnpoints(); 

hope helps 1 weird issue had. suggestions @petr , @chazsolo


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -