JavaScript get label text | Simple example code

Use the innerHTML property to get the text value of the label in JavaScript. The innerHTML property sets or returns the HTML content of an element.

var value = document.getElementById('idName').textContent

If you need to target < IE9 then you need to use .innerText

JavaScript get label text Example

HTML example code:

You can get the value of any label or any other element is selected by its attribute id:

<!DOCTYPE html> 

	<label id = "lb"> Fetch me 10000 </label> 
	<button onclick="getTxt()"> Click Here </button> 

		function getTxt() { 
			var value = document.getElementById('lb').innerHTML;



JavaScript get label text example code

Do comment if you have any doubts on this basic JS topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.