Click here to Skip to main content
11,496,146 members (347 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: Javascript jQuery
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 8-Feb-12 21:04pm
Comments
SAKryukov at 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/[^].

labelText = $("#myLabel").text()
were the label or any other element is selected by its attribute id:
<label id="myLabel" for="male">Male</label>


—SA
  Permalink  
v3
Comments
Abhinav S at 9-Feb-12 2:21am
   
My 5.
SAKryukov at 9-Feb-12 2:22am
   
Thank you, Abhinav.
--SA
thatraja at 9-Feb-12 2:40am
   
5!
Espen Harlinn at 9-Feb-12 8:44am
   
5'ed!
<label id="Label1">labeltext spantext</label>
<script>
  var lbltext = document.getElementById('Label1').innerHTML;
</script>
  Permalink  
v2
Comments
Abhinav S at 9-Feb-12 2:20am
   
My 5. However is this not for setting a label value rather than getting the value?
SAKryukov at 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 at 9-Feb-12 2:27am
   
Yes. Not much of a change while reading. ;)
Yes I did see your answer. It an elegant solution.
thatraja at 9-Feb-12 2:39am
   
Updated
Abhinav S at 9-Feb-12 2:49am
   
Cool.
SAKryukov at 9-Feb-12 2:21am
   
Good enough, a 5, but jQuery is more elegant -- please see my answer.
--SA
Espen Harlinn at 9-Feb-12 8:44am
   
5'ed!
Try document.getElementsByTagName('label')[0].firstChild.data.
  Permalink  
Comments
SAKryukov at 9-Feb-12 2:25am
   
It can read! A 5.
--SA
Abhinav S at 9-Feb-12 2:28am
   
Thank you SA.
thatraja at 9-Feb-12 2:40am
   
5!
Abhinav S at 9-Feb-12 2:48am
   
Thanks thatraja.
kpkaran88 at 9-Feb-12 3:20am
   
thank you Abinav
using ur code i done that work..
Espen Harlinn at 9-Feb-12 8:37am
   
5'ed!
var amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML;
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 26 Sep 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100