When Visible=false is used, the control will not render so it cannot be found.
You can use a CSS style: visibility:hidden
There was some confusion between val() and text()
val() is used to get and set text from input controls (textboxes, radio buttons, checkboxes, select, textarea).
text() is used to get text from NON-input elements: From the documenation: Get the combined text contents of each element in the set of matched elements, including their descendants.
And if you don't want the label to occupy any space on the page when hidden then use the style
display: none instead. That's what I use in almost all cases.
tripati_tutu
Member
30 Points
53 Posts
How to get a label control value by using its class name?
Feb 15, 2012 04:25 AM|LINK
Hi,
I have one label control as
So I am assigning some value to this label control. So how I will get that assigned value by using its class name in jQuery.
Please help me.
Thanks.
abiruban
All-Star
16038 Points
2734 Posts
Re: How to get a label control value by using its class name?
Feb 15, 2012 04:32 AM|LINK
Hi
$(".label1css").val();***DON'T FORGET TO CLICK “MARK AS ANSWER” ON THE POST IF HELPED YOU.
me_ritz
Star
9337 Points
1447 Posts
Re: How to get a label control value by using its class name?
Feb 15, 2012 04:33 AM|LINK
Remove visible=false attribute from your label control...otherwise jquery would have nothing to pick up.
Once you remove the attribute, use this code:
$(document).ready(function () {
alert($(".label1css").text());
});
devensawant
Contributor
3763 Points
858 Posts
Re: How to get a label control value by using its class name?
Feb 15, 2012 04:33 AM|LINK
Not sure but try
$("span.label1css").value;If my post helps you then please mark as answer
SGWellens
All-Star
126031 Points
10310 Posts
Moderator
Re: How to get a label control value by using its class name?
Feb 15, 2012 12:46 PM|LINK
To clarify:
When Visible=false is used, the control will not render so it cannot be found.
You can use a CSS style: visibility:hidden
There was some confusion between val() and text()
val() is used to get and set text from input controls (textboxes, radio buttons, checkboxes, select, textarea).
text() is used to get text from NON-input elements: From the documenation: Get the combined text contents of each element in the set of matched elements, including their descendants.
My blog
MetalAsp.Net
All-Star
112151 Points
18246 Posts
Moderator
Re: How to get a label control value by using its class name?
Feb 15, 2012 12:57 PM|LINK
And if you don't want the label to occupy any space on the page when hidden then use the style display: none instead. That's what I use in almost all cases.