The textContent in Javascript18 Mar 2025 | 6 min read The JavaScript textContent property works to set and get the page's text content. It is used to pass and display the text content of some information, tags, and large size of data and its nodes. The TextContent varies from the nodeValue of the script tag and returns content from child nodes of the multiple data types. If the node is a text node, a processing instruction, or a tag remark, then javascript textContent gets or sets the text. The TextContent shows the concatenation of the textContent of each child node. It shows the processing instructions and comments to the other node types. SyntaxThere are two syntaxes available for the JavaScript text content. The first syntax uses to set the text of a node, and the second syntax uses to retrieve the node's text. Syntax 1: The following syntax uses to set the node's text using textual content. Syntax 2: The following syntax uses textual content to get the node's text. Return Value:
ExamplesThe following examples show the set and get the various type of information using the textContent attribute. Example 1 The following example uses text content in the javascript to set the information. The node data shows the text of the tags. Output The following image shows the set the data using the content node. ![]() Example 2 The following example uses text content in the javascript to get the information. We can get the value of the click function's button. Output The following image shows the set the data using the content node. ![]() Example 3 The following example uses text content in the javascript to get the information. We can get the value of the click function's button. Output The following image shows the set the data using the content node. ![]() Example4 The following example uses text content on the button value to get and set the information. We can get the value after clicking the button. Output The following image shows the set the data using the content node. ![]() Example5 The following example uses to get and set the information using innerHtml, innerText, and text content on the button value. We can get the difference in the output data after clicking the button. Output The following image shows the set the data using the content node. ![]() Example 6 The following example uses to get the list data and set the information using text content on the onclick button value. We can get the data of the list and other tags information. Output The following image shows the set the data using the content node. ![]() Example 7 The text content does not support empty data if information or string is empty. It shows the empty string as a value. Output The following image shows the get the data using text content node. ![]() Key Point of the text content in javascript
ConclusionThe text content displays multiple types of information. The html tag required information and list data shown using a single method. Next TopicJavaScript Throttling |
Base64 is a binary-to-text encoding system that converts binary data into a radix-64 representation and then encodes it as an ASCII string. It is frequently used to store data in files and send data over the internet. With native JavaScript functions and modules, Base64 data...
3 min read
? A WebSocket is a continuous two-way communication channel between clients and servers. The client could be any web browser, and the server could be any backend system. Using the HTTP request/response connections, the WebSocket can transmit any number of protocols and can provide server-to-client information...
8 min read
This article will discuss the Fibonacci series and how we can generate the . It is a series that generates subsequent series of numbers by the addition of the two ious numbers. The first two terms of the Fibonacci series are zero & one, respectively. And...
7 min read
As we know that arrays are helpful in storing data in a sequence in the memory. But sometimes, there may be chances that we may store the same value or duplicate values in an array. Thus, we need to remove such duplicate values from the...
4 min read
Pressing and releasing the left mouse button is an important feature of the mouse event function. The left side button uses for many functionalities to work, but the user uses the right side button for the same functionality. We can restrict the mouse event with the...
5 min read
Introduction: JavaScript objects are made up of properties, which are just key-value pairs. In essence, properties consist of a pair of keys and values that can represent any type of entity. Even functions have the ability to function as a value or a key in any...
3 min read
When a user tries to load a page but it is unsuccessful, the page remains unloaded, and a JavaScript onunload event is triggered. The possibility exists that the onunload event will also happen if the browsers have been closed while the page is loaded. When a...
3 min read
The onbeforeunload Event happens just before a document is unloaded. It displays a statement in a confirmation dialogue box to stay current page or go to the page using the provided link. You may ask the user whether they wish to stay on the...
4 min read
The mouse rolls up or down the web page and starts to operate the mouse wheel function using the "onwheel" javascript. We can use the "onmousewheel" event, but it deprecates in the javascript. We can use the javascript for the "onwheel" attribute instead of the "onmousewheel" event. Syntax The...
3 min read
In this article, we are going to discuss about the formatting of numbers with commas in JavaScript. Sometimes, we require formatting a number with commas in the HTML page in order to make it easy to read. Using JavaScript, we can transform a number into...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India