getting the text inside a tag from meteor expression -
the code below suppose text insdie of list, if task1 clicked alert should task1, if task2 clicked, alert says text2...
when click on of link, no alert shows let along message. must doing wrong. pleas help. thanks
template.mainmenu.helpers({ menuitems: [ {menuitem: "task1"}, {menuitem: "task2"}, {menuitem: "task3"}, {menuitem: "task4"}, {menuitem: "task5"}, {menuitem: "task6"}, {menuitem: "task7"} ] }); template.mainmenu.events({ 'click .menuitem': function(){ alert(event.target.menuitem.value); } });
<template name="mainmenu"> <div class="container"> <div class="row"> <section class="col-xs-12"> <div class="list-group"> {{#each menuitems}} <a href="#" class="list-group-item menuitem"> <img src="/abc.png"> {{menuitem}} <span class="badge">></span> </a> {{/each}} </div> </section> </div> </div> </template>
you haven't defined argument (event) of function. below example understand code throwing uncaught errors.
template.mainmenu.events({ 'click .menuitem': function(event){ try{ alert(event.target.menuitem.value); } catch (e){ alert(e) } } });
update
add data-value={{menuitem}}
link , try value using jquery:
<template name="mainmenu"> <div class="container"> <div class="row"> <section class="col-xs-12"> <div class="list-group"> {{#each menuitems}} <a href="#" class="list-group-item menuitem" data-value={{menuitem}}> <img src="/abc.png"> {{menuitem}} <span class="badge">></span> </a> {{/each}} </div> </section> </div> </div> </template> template.mainmenu.events({ 'click .menuitem': function(event){ try{ alert($(event.currenttarget).data('value')); } catch (e){ alert(e) } } });
Comments
Post a Comment