javascript - If text box value matches then make that specific label text to yes else no -


iam trying check if text of label matches text box if matches make specific label text yes else no in code not sure wrong not happening showing "no" self

demo

html

<input class="master" value="1">      <label class="user_label" >1</label>             <label class="user_label" >0</label>         <label class="user_label" >1</label> 

js:

$(function() {       var master = $('input.master').get(0).value; // master value     var fn = function() {         return this.text === master ? "yes" : "noo";//if current text-box matches master,then yes else no      };     $('label.user_label').text(fn); // loop , replace text each user input   }); 

this.text undefined inside fn, because this dom node, , doesn't have text property.

you can wrap jquery object , use text() method:

var fn = function() {     return $(this).text() === master ? "yes" : "noo"; } 

http://jsfiddle.net/l6d39f10/5/


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -