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
SAKryukov at 9-Feb-12 2:23am
What part of the Web has banned you? Google? Bing?... :-)
Use the jQuery method .text(), see[^].

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

Abhinav S at 9-Feb-12 2:21am
My 5.
SAKryukov at 9-Feb-12 2:22am
Thank you, Abhinav.
thatraja at 9-Feb-12 2:40am
Espen Harlinn at 9-Feb-12 8:44am
<label id="Label1">labeltext spantext</label>
  var lbltext = document.getElementById('Label1').innerHTML;
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. :-)
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
Abhinav S at 9-Feb-12 2:49am
SAKryukov at 9-Feb-12 2:21am
Good enough, a 5, but jQuery is more elegant -- please see my answer.
Espen Harlinn at 9-Feb-12 8:44am
Try document.getElementsByTagName('label')[0]
SAKryukov at 9-Feb-12 2:25am
It can read! A 5.
Abhinav S at 9-Feb-12 2:28am
Thank you SA.
thatraja at 9-Feb-12 2:40am
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
var amount = document.getElementById("<%=lblAmount.ClientID %>").innerHTML;

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