Questions tagged [createtextnode]

This method is used to create a new text node within the HTML/XML document.

Description

The .createTextNode() method is used to create a new text node within the HTML/XML document.

Syntax

text = document.createTextNode(data);

where,

  • text is a Text node.
  • data is a string containing the data to be put in the text node.

References

  1. createTextNode - W3C Spec
  2. createTextNode - MDN Link
49 questions
43
votes
1 answer

TextNode or textContent?

What's the advantage of creating a TextNode and appending it to an HTML element over setting directly its textContent? Let's say I have a span. var span = document.getElementById('my-span'); And I want to change its text. What's the advantage of…
Flyaku
  • 468
  • 1
  • 4
  • 7
41
votes
3 answers

How do I add a non-breaking whitespace in JavaScript without using innerHTML?

I'm generating content dynamically and in some instances, I need to set a   as the only content of a element. However, the following adds   as text vs adding a empty space: var foo = document.createElement("span") foo =…
frequent
  • 27,643
  • 59
  • 181
  • 333
37
votes
3 answers

Is there any major difference between innerHTML and using createTextNode to fill a span?

The title is pretty clear: Is there any major difference between innerHTML and createTextNode (used with Append) to fill a span with text?
Jeff Noel
  • 7,500
  • 4
  • 40
  • 66
11
votes
5 answers

Why isn't there a document.createHTMLNode()?

I want to insert html at the current range (a W3C Range). I guess i have to use the method insertNode. And it works great with text. Example: var node = document.createTextNode("some text"); range.insertNode(node); The problem is that i want to…
Martin
  • 5,197
  • 11
  • 45
  • 60
8
votes
5 answers

How do I prevent Php's DOMDocument from encoding html entities?

I have a function that replaces anchors' href attribute in a string using Php's DOMDocument. Here's a snippet: $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadHTML($text); $anchors = $doc->getElementsByTagName('a'); foreach($anchors as…
thesmart
  • 2,993
  • 2
  • 31
  • 34
6
votes
3 answers

Using createTextNode() but I need to add HTML tags to it (JavaScript/JQuery)

When I click an item in a table, I need it to add that item to a list and display that list. Here's my code for adding/displaying the items in the list: var myList = document.getElementById('my-list'); function addItemToList(id) { …
Nathan R
  • 840
  • 5
  • 13
  • 32
6
votes
3 answers

How to append an HTML string to a DocumentFragment?

I'm adding textnodes to a documentFragment like this: var foo = document.createDocumentFragment(); var someText = "Hello World"; foo.appendChild(document.createTextNode(someText)); This works fine, but sometimes I'm being passed "text" which…
frequent
  • 27,643
  • 59
  • 181
  • 333
5
votes
1 answer

How to avoid escaping & while escaping " with \"

As a special requirement, I have been trying to escape " with \" while writing XML using DOM. Unfortunately, when I write text with Document.createTextNode(TextValue), it outputs \". However, the expected is \" Details: Writing…
Indigo
  • 2,887
  • 11
  • 52
  • 83
3
votes
4 answers

JavaScript TextNode update

If I have a var t = document.createTextNode(text) parent.appendChild(t); Is it possible to simply update the contents of t? I would like to change the text inside the parent without using removeChild, createTextNode and appendChild. Why would I…
Tom
  • 6,991
  • 13
  • 60
  • 78
3
votes
0 answers

Integers in TextNodes w/ Python minidom

I am working on an API using SOAP and WSDL. The WSDL expects integers to come through. I am fairly new to ALL of this, and constructing XML in Python. I have chosen to use minidom to create my SOAP message. So using minidom, to get a value into a…
KacieHouser
  • 1,885
  • 4
  • 22
  • 35
3
votes
2 answers

Getting HTML entities into document.createTextNode

Suppose I have a string created like this: str = '\\' + 'u00eb'. If I do document.createTextNode(str), it will give me '\u00eb', instead of ë. Dont't ask me why, but I can't define my string as str = '\u00eb'. Defining my string as str = 'ë' or…
Spifff
  • 748
  • 6
  • 14
3
votes
2 answers

javascript Replacing \n with
inside createTextNode

I have a String with \n - line breaks in Javascript, that I want to replace for another text using createTextNode() in Javascript.