javascript - How to get the span text content within template -


i have problem using jquery retrieve span element within template. here code:

template.item.events({ 'click .remove':function(event,tpl){         meteor.call('tasks.remove',this._id);         var docemail=tpl.find('#docname');         alert(docemail.text());         meteor.call('doc.removeauthorization', docemail, this._id);      },}); 

my definition of template:

<template name="item">  <li class="{{#if ischecked}}mychecked{{/if}}">    <input type="checkbox" checked="{{ischecked}}" class="check-box"/>    <strong><span name="docemail" id="docname">{{content}}></span></strong>    <span> {{creattime}}</span>    <button class="remove">&times;</button>         </li></template> 

here how template placed in body:

<ul> {{#each tasks}}     <li>{{> item}}</li> {{/each}} </ul> 

i have read many posts on how use jquery or jscript span text. think have tried of them. gave me similar error:

body.js:162 uncaught typeerror: cannot read property 'text' of null

i tried using , tpl.find(".docname"). got same type of error.

also tried tpl.$(). same error.

is because span element did not exist when template.find() function called?

but have seen people using similar code dom element(other span text) success.

i thought tasks.remove might have remove text before jquery called. changed order of calling 2 meteor.call s. this:

template.item.events({ 'click .remove':function(event,tpl){         meteor.call('tasks.remove',this._id);         var docemail=tpl.find('#docname');         alert(docemail.value);         meteor.call('doc.removeauthorization', docemail, this._id);      },}); 

now undefined alert. if use docemail.val() or docemail.text(), "docemail.val() not function.".

hope guys can shed light on it! thank you!

i think it's useful:

$( "span" ).each(function( index ) {   console.log( index + ": " + $( ).text() ); }); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -