Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
See more:
i have one label and one span.the span is placed inside the label.I want to get only the label text.. how to get the text..
  • <label>labeltext spantext</label>
Posted
Comments
Sergey Alexandrovich Kryukov 9-Feb-12 2:23am    
What part of the Web has banned you? Google? Bing?... :-)
--SA

Use the jQuery method .text(), see http://api.jquery.com/text/[^].

JavaScript
labelText = $("#myLabel").text()

were the label or any other element is selected by its attribute id:
XML
<label id="myLabel" for="male">Male</label>



—SA
 
Share this answer
 
v3
Comments
Abhinav S 9-Feb-12 2:21am    
My 5.
Sergey Alexandrovich Kryukov 9-Feb-12 2:22am    
Thank you, Abhinav.
--SA
thatraja 9-Feb-12 2:40am    
5!
Espen Harlinn 9-Feb-12 8:44am    
5'ed!
HTML
<label id="Label1">labeltext spantext</label>

XML
<script>
  var lbltext = document.getElementById('Label1').innerHTML;
</script>
 
Share this answer
 
v2
Comments
Abhinav S 9-Feb-12 2:20am    
My 5. However is this not for setting a label value rather than getting the value?
Sergey Alexandrovich Kryukov 9-Feb-12 2:22am    
Right, but with little fantasy it could be modified to read :-)
Using jQuery is more elegant, please see my answer. :-)
--SA
Abhinav S 9-Feb-12 2:27am    
Yes. Not much of a change while reading. ;)
Yes I did see your answer. It an elegant solution.
thatraja 9-Feb-12 2:39am    
Updated
Abhinav S 9-Feb-12 2:49am    
Cool.
Try document.getElementsByTagName('label')[0].firstChild.data.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Feb-12 2:25am    
It can read! A 5.
--SA
Abhinav S 9-Feb-12 2:28am    
Thank you SA.
thatraja 9-Feb-12 2:40am    
5!
Abhinav S 9-Feb-12 2:48am    
Thanks thatraja.
[no name] 9-Feb-12 3:20am    
thank you Abinav
using ur code i done that work..
var amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900