Questions tagged [textnode]

textNodes in DOM, HTML, XML are nodes which contain only text, rather than the other node types of element, comment, and processing instruction.

textNodes in DOM, HTML, XML are nodes which contain only text, rather than the other node types of element, comment, and .

191 questions
92
votes
7 answers

getElementsByTagName() equivalent for textNodes

Is there any way to get the collection of all textNode objects within a document? getElementsByTagName() works great for Elements, but textNodes are not Elements. Update: I realize this can be accomplished by walking the DOM - as many below…
levik
  • 114,835
  • 27
  • 73
  • 90
78
votes
6 answers

Hide text node in element, but not children

I'm having a little trouble with CSS and can't seem to find a solution. I have this HTML Now I want to hide the text «Click to close» only, without hiding neither the div, nor the…
elveti
  • 2,316
  • 4
  • 20
  • 27
66
votes
2 answers

What Is A Text Node, Its Uses? //document.createTextNode()

So I've been slowly replacing a lot of my normal jQuery code with native javascript, and I happened upon the document.createTextNode() and related MDN documentation. After reading I'm somewhat confused what a text node is. I understand it can be…
AlbertEngelB
  • 16,016
  • 15
  • 66
  • 93
58
votes
1 answer

When working with text nodes should I use the "data", "nodeValue", "textContent" or "wholeText" field?

Possible Duplicate: How to retrieve the text of a DOM Text node? In my experiments to handle DOM mutation observers I've noticed that when the target is a text node there are four fields all containing the new text of the…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
41
votes
4 answers

How to get text node after element?

Using jQuery. I have the following html: All the world
How would I get ONLY the text. what selector should I use? (I need the "All the world") I also can not touch the HTML...
Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
29
votes
4 answers

Replace a textNode with HTML text in Javascript?

I was directed to the Linkify project on GitHub (https://github.com/cowboy/javascript-linkify) for finding and "linkifying" URLs and domains just floating in text. It's awesome! It totally works on text! However, I'm not quite sure how to make it…
Jippers
  • 2,635
  • 5
  • 37
  • 58
27
votes
5 answers

Insert HTML into text node with JavaScript

I've got a little text node: var node And I want to wrap a span around every occurrence of "lol". node.nodeValue = node.nodeValue.replace(/lol/, "lol") It it prints out "lol" when I want "lol" as a span element.
alt
  • 13,357
  • 19
  • 80
  • 120
22
votes
2 answers

Is there an equivalent to getBoundingClientRect() for text nodes?

Is there a way to get the bounding rect of a text node? The getBoundingClientRect() method is defined on elements only, and the parent element is bigger then the actual text node.
user163369
  • 265
  • 1
  • 2
  • 6
20
votes
6 answers

Retrieving DOM textnode position

Is it possible to retrieve the geometric position (i.e. top/left offsets from either the parent element, the page, etc) of a text node?
dpq
  • 9,028
  • 10
  • 49
  • 69
17
votes
2 answers

How can I replace a Java Jackson TextNode by another one (update)?

My goal is to update some textual fields in a JsonNode. List list = json.findValues("fieldName"); for(JsonNode n : list){ // n is a TextNode. I'd like to change its value. } I don't see how this could be done. Do you…
yo_haha
  • 359
  • 1
  • 4
  • 15
16
votes
3 answers

jQuery select and wrap textNode

I want to select the text inside the div element and wrap it with a tag. The tag should only wrap to text inside div and not text inside a child element such as the

tag in this example.

Testing

Some more text inside p

Pinkie
  • 10,126
  • 22
  • 78
  • 124
15
votes
3 answers

JS DOM: Get elements by text content

I am looking for a way to perform fulltext search on the DOM tree with JS. In two words, I would like to retrieve the list of text nodes which contain a given string. I've tried mootools' Element.getElements ( ':contains[string]' ) but I can't get…
Hristo
  • 740
  • 2
  • 7
  • 19
14
votes
1 answer

Find all text nodes

I'm trying to write a bookmarklet that calls the function doSomething(textNode) on all instances of visible text on the document. doSomething(), just for fun, replaces every word with "derp" by replacing the textContent of the textNode passed into…
Rahat Ahmed
  • 2,191
  • 2
  • 30
  • 40
12
votes
1 answer

JavaScript: Add elements in textNode

I want to add an element to a textNode. For example: I have a function that search for a string within element's textNode. When I find it, I want to replace with a HTML element. Is there some standard for that? Thank you.
thomas
  • 121
  • 1
  • 3
10
votes
1 answer

Typescript: The type of TextNode

If you write below code: const e = document.body.firstChild; if (e.nodeType === Node.TEXT_NODE) console.log(e.data); You will get this error on e.data: TS2339: Property 'data' does not exist on type 'ChildNode'. While if the condition be true…
Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100
1
2 3
12 13