Click here to Skip to main content
12,950,184 members (74,148 online)
Rate this:
 
Please Sign up or sign in to vote.
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 8-Feb-12 20:04pm
Comments
SAKryukov 9-Feb-12 2:23am
   
What part of the Web has banned you? Google? Bing?... :-)
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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 9-Feb-12 2:21am
   
My 5.
SAKryukov 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!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

<label id="Label1">labeltext spantext</label>

<script>
  var lbltext = document.getElementById('Label1').innerHTML;
</script>
  Permalink  
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?
SAKryukov 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.
SAKryukov 9-Feb-12 2:21am
   
Good enough, a 5, but jQuery is more elegant -- please see my answer.
--SA
Espen Harlinn 9-Feb-12 8:44am
   
5'ed!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Try document.getElementsByTagName('label')[0].firstChild.data.
  Permalink  
Comments
SAKryukov 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.
kpkaran88 9-Feb-12 3:20am
   
thank you Abinav
using ur code i done that work..
Espen Harlinn 9-Feb-12 8:37am
   
5'ed!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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
Top Experts
Last 24hrsThis month
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 26 Sep 2014
Copyright © CodeProject, 1999-2017
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