Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
In addition to the innerHTML property, you can also use the childNodes
and nodeValue
properties to get the content of
an element. The following example collects the node value of an h1 element and copies it into a p element:
Hello!
// This looks for the first child node of the identified element and gets it's value.
// The first one of having an index of 0.
let myText = document.getElementById("intro").childNodes[0].nodeValue;
// This takes that obtained value from above and puts it inside of 'demo1'.
document.getElementById("demo1").innerHTML = myText;