Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assigning value to label using JQuery?

I am using JQuery 1.8.3. I have below HTML label.

<label for="myalue" style="vertical-align: middle"></label>

Now using JQuery i need to set a string to above label and am trying as below.

 $("label[for='myalue']").text("someText");

Above code works only in IE. But in Firefox label value is not set.

Any suggestions?

Thanks!

like image 942
user755806 Avatar asked Jan 09 '14 06:01

user755806


1 Answers

You should be able to use

$("label[for='myalue']").html("someText");

or

$("label[for='myalue']").text("someText");

The only difference between html & text is that:

html() get/set HTML of an element

text() get/set innertext of an element

In you case I would use text() as it should be faster (at least looking at the jquery code). I've just tested both of this functions in chrome, IE9 and firefox and they work fine with label tag.

like image 54
Arek S Avatar answered Sep 22 '22 10:09

Arek S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!