How to get the text without HTML element using JavaScript ? Last Updated : 07 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Given an HTML document containing some elements and the task is to get the text inside an HTML element using JavaScript. There are two methods to get the text without HTML element which are listed below: Using innerText propertyUsing textContent property Using innerText property: We can use innerText property to get the text from HTML element. Example: html <!DOCTYPE html> <html> <head> <title> Get the text inside HTML element using JavaScript </title> </head> <body> <div class="main"> Welcome to GeeksforGeeks </div> <script> const div = document.querySelector('.main'); alert(div.innerText); </script> </body> </html> Output: Using textContent property: We can also use textContent property to get the text from HTML element. Example: html <!DOCTYPE html> <html> <head> <title> Get the text inside HTML element using JavaScript </title> </head> <body> <div class="main"> Welcome to GeeksforGeeks </div> <script> const div = document.querySelector('.main'); alert(div.textContent); </script> </body> </html> Output: Let us compare the properties of the two methods: innerTexttextContentIt returns human-readable contentIt returns texts along with the tagIt returns only styling elements and not the hidden elementsIt returns all elements including hidden elementsIt is defined only for HTMLElement objectsIt is defined for all Node objects Comment More infoAdvertise with us Next Article How to get the text without HTML element using JavaScript ? F frikishaan Follow Improve Article Tags : JavaScript Web Technologies HTML Write From Home JavaScript-Questions +1 More Similar Reads How to loop through HTML elements without using forEach() loop in JavaScript ? In this article, we will learn how to loop through HTML elements without using the forEach() method. This can be done in the following ways: Table of Content Approach 1: Using the for loopApproach 2: Using the While loopApproach 3: Using the 'for.....of' statementApproach 4: Using the for...in state 4 min read How to get/change the HTML with DOM element in JavaScript ? In order to get/access the HTML for a DOM element in JavaScript, the first step is to identify the element base on its id, name, or its tag name. Then, we can use inner.HTML or outer.HTML to get the HTML. Using the getElementById() method: This method gets/identifies the DOM elements using its ID an 3 min read How to Get the Content of an HTML Comment using JavaScript ? In this article, we will learn how to get the content of an HTML Comment Using Javascript. Comments are a best practice in programming and software development. In general, they can explain why a coding decision was made or what needs to be done to improve the code you're working on. HTML tags (incl 3 min read How to get the outer html of an element using jQuery ? Sometimes, there is a need to get the entire HTML element by its id and not merely its contents, for doing so, we shall use the HTML DOM outerHTML Property to get the outer HTML of HTML element. Syntax: document.getElementById("your-element-id").outerHTML) You can use a variable and initialize it to 2 min read How to select all Text in HTML Text Input when clicked using JavaScript? To select the text in HTML Text Input we can use the JavaScript DOM methods and we will select the text when we click the text box.Using document.getElementById() methodSyntax:<input onClick="this.select();" > or document.getElementById("ID").select();Example 1: We will use "this.select()" in 1 min read Like