Text nodes are a type of node that denotes the actual text inside an element. The textNodes of any element can be selected using jQuery by selecting all the nodes and using the filter() method to check the nodeType property.
The required element is first selected using the jQuery selector. The contents() method is used on selected elements. This method is used to return the direct children of an element including all the text and comment nodes.
The filter() method is used on these returned elements to filter only the text nodes required. The custom filter function checks if the nodeType property of the nodes return equal to the Node.TEXT_NODE value.
The “Node.TEXT_NODE” value is used to identify a text node from other nodes. Alternatively, the integer value “3” could also be used to identify a text node. The filter() method will now only return the nodes that are textNodes. Therefore this method can be used to select the textNodes of any element.
- How to select text input fields using CSS selector ?
- How to remove options from select element using jQuery ?
- How to select ID that starts with certain character using jQuery ?
- How to add options to a select element using jQuery?
- How to select first element in the drop-down list using jQuery ?
- How to fire an event on file select using jQuery ?
- How to select all on focus in input using JQuery?
- How to select all elements without a given class using jQuery ?
- How to select html element using ID in jQuery when ID contains a dot character ?
- How to get N options from the <select> element using JQuery?
- How to select a div with a certain class using jQuery ?
- How to select an element with multiple classes using jQuery ?
- How to select all elements that contains some specific CSS property using jQuery ?
- How to Select a Range of Elements using jQuery ?
- How to select the last row of a table using jQuery ?
- How to select all visible or hidden elements in a HTML page using jQuery ?
- HTML | DOM Input Text select() Method
- jQuery | select() with Examples
- How to select an element by name with jQuery?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.