| Author: Amer Sohail 19 Feb 2009 | Member Level: Bronze Points : 2 |
html label control does not contain any value attribute like input controls infact text is written as a text node inside HTML i.e. Whenever you have to acces or assign this type of text, use innerText property of Node. so following code snippet will be used to acces label's text document.getElementById('heading').innerText Above code works great in IE but not in other browsers like Firefox, Safari etc. Reason is that IE provides a non standard facility to get text of a node. DOM specification says that "This is heading" is a child node of type text of label node. so first of all we have to navigate to that child node and then get value of that child node through nodeValue attribute. This will work in each browser including IE and firefox.
document.getElementById("heading").childNodes[0].nodeValue
for more details visit http://sites.google.com/site/technicalinfosite/tips---techniques/howtogetorassignvaluetohtmllabelthroughjavascript
|
| Author: Macolee 19 Feb 2009 | Member Level: Silver Points : 1 |
The innerText property will not work in FF. An asp.net label is replaced by a span tag. we can get the text of label with: document.getElementById('<% lbl.ClientID %>').innerHTML
|