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
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"; }
Comments
Post a Comment