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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -