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.

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

JavaScript get label text Example

HTML example code:

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

Output:

JavaScript get label text example code

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

Note: 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.