How to use the HTML DOM createTextNode() Method
More ventures into the DOM
I came across this method while poking around the W3C documentation and tutorials and when I came across a way to display the html of a webpage on an iPad. This was in conjunction with the createElement() Method and the HTML DOM appendChild() Method
In keeping with a lot of my other coding I am trying to investigate techniques as I come across them. This is a different approach to being taught these techniques. In most cases I create a webpage on a piece of code that I am actually using.
The W3C Example:
The JavaScript
function myFunction() {
var para = document.createElement("P");
var t = document.createTextNode("This is a paragraph."); // Create a text node
para.appendChild(t);
// Append the text to <p>
}
How I saw this used
When I was looking for a way to view the html code of my pages on my iPad Pro I came across an Apple blog/website post on how to add JavaScript code to a bookmark. The JavaScript creates a pew page, in a new tab, that is built by creating, appending and adding to the HTML on that new page.
innerText vs. innerHTML
In the example for create_textnode Method there is no need to assign the value of a var to an element before it is appended. This can be done using the createTextNode method. The second example does not use this!