Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  104] [ 4]  / answers: 1 / hits: 132983  / 11 Years ago, mon, october 7, 2013, 12:00:00

I have a usual label


<label class="mytxt"  style="color: #662819;" id ="telefon"></label>

I am setting a value like this:


document.getElementById('telefon').innerHTML = userDetails.phone;

after a label has some value like "123".


In a pagesource, I have a label without setted value inside "><" but I see as output it alright:


pagesource: <label class="mytxt"  style="color: #662819;" id ="telefon"></label>

My problem is when I like to GET a value.
I tried standards like:


value = $("#telefon").val(); 
document.getElementById('telefon').value

Nothing works, value is always "not defined". Why is this so, even if I see it in the browser?


More From » jquery

 Answers
3

You need text() or html() for label not val() The function should not be called for label instead it is used to get values of input like text or checkbox etc.



Change



value = $(#telefon).val(); 


To



value = $(#telefon).text(); 

[#75171] Sunday, October 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ravenl questions
Thu, Feb 18, 21, 00:00, 3 Years ago
Tue, Jan 12, 21, 00:00, 3 Years ago
Tue, Mar 17, 20, 00:00, 4 Years ago
;