javascript - How to wait rendering before acting on click event? -


this issue not shows up. works fine if wait time page load or, if wait enough between clicks change language on drop-down menu. simple multi-language website.

my drop-down in nav-bar looks like:

    ....     <li class="dropdown">        <a class="dropdown-toggle" data-toggle="dropdown" href="#"> <img src="pictures/br-us-sp.png"><b class="caret"></b></a>               <ul class="dropdown-menu" id="langmenu">                   <li><a href="#" id="pt-br" name="pt-br" value="pt-br"><img src="/pictures/1383607461_brazil.png"></a></li>                 <li><a href="#" id="en" name="en" value="en"><img src="/pictures/1383615303_united-states.png"></a></li>                   <li><a href="#" id="es" name="es" value="es"><img src="/pictures/1383615325_spain.png"></a></li>                   <li class="divider"></li>               </ul>       </li>      .... 

and events looks like:

template.navigation.events({ 'click #langmenu': function(event){         currentlang = $(event.target).attr('id');   ...    // stuff , re-renders page upon value of currentlang //   ...  } }); 

when breaks, console shows variable currentlang undefined. assuming because template not rendered in time click event pick value. assumption correct?

how make sure currentlang value?

sorry. have spent couple days goggling out . meteor evolves fast, confused many possible solutions found , tested did not work (deprecated?). can't meteor docs how use blaze functions, when , how use onrendered, etc... there examples?

instead, should use different approach using iron router? if yes, how?

you have block out. current es5 method of doing be

template.navigation.events({ 'click #langmenu': function(event){         settimeout(function(){             currentlang = $(event.target).attr('id');         },100)  } }); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -