Ready. Start with one instruction.
Loading the learning workspace…
FROM YOUR FIRST INSTRUCTION TO A WORKING APPLICATION
Learn JavaScript from scratch through small working examples, visual experiments and complete projects. No account or AI key required.
Predict → Experiment → Build → Test → Explain
Ready. Start with one instruction.
Loading the learning workspace…
A DOM tree contains more than elements. Text inside an element is represented by a text node. children lists element children; childNodes includes text and comments too. Whitespace between tags may therefore change a childNodes count. Use the collection that matches your intent rather than assuming every node is an element. This fixture deliberately includes a text node followed by a strong element. The document is a tree of element and text nodes. Inspect the live tree after running a change.
document.querySelector('#result').textContent = document.querySelector('#line').childNodes[0].nodeType;Run the preview tests; inspect the live page.
A DOM tree contains more than elements. Text inside an element is represented by a text node. children lists element children; childNodes includes text and comments too. Whitespace between tags may therefore change a childNodes count. Use the collection that matches your intent rather than assuming every node is an element. This fixture deliberately includes a text node followed by a strong element.
document.querySelector('#result').textContent = document.querySelector('#line').childNodes[0].nodeType;Read or update literal text in the selected element. It does not parse user input as HTML.
document.querySelector('#result').textContent = document.querySelector('#line').childNodes[0].nodeType;
console.log(document.querySelectorAll("*").length);Interact with the preview; the diagnostic displays its actual element count.
A DOM tree contains more than elements. Text inside an element is represented by a text node. children lists element children; childNodes includes text and comments too. Whitespace between tags may therefore change a childNodes count. Use the collection that matches your intent rather than assuming every node is an element. This fixture deliberately includes a text node followed by a strong element. The document is a tree of element and text nodes. Inspect the live tree after running a change. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
document.querySelector('#result').textContent = document.querySelector('#line').childNodes[0].nodeType;Read or update literal text in the selected element. It does not parse user input as HTML.
console.log(document.querySelectorAll("*").length);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
document.querySelector('#result').textContent = document.querySelector('#line').childNodes[0].nodeType;
console.log(document.querySelectorAll("button").length);Interact with the preview; the diagnostic displays its actual element count.
A DOM tree contains more than elements. Text inside an element is represented by a text node. children lists element children; childNodes includes text and comments too. Whitespace between tags may therefore change a childNodes count. Use the collection that matches your intent rather than assuming every node is an element. This fixture deliberately includes a text node followed by a strong element. The document is a tree of element and text nodes. Inspect the live tree after running a change. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
document.querySelector('#result').textContent = document.querySelector('#line').childNodes[0].nodeType;Read or update literal text in the selected element. It does not parse user input as HTML.
console.log(document.querySelectorAll("button").length);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
Show the nodeType of the first child of #line in #result.
// Show the nodeType of the first child of #line in #result. // Write your JavaScript below.
document.querySelector('#result').textContent = document.querySelector('#line').childNodes[0].nodeType;A text node has nodeType 3.
Which operation changed the result, why did it work, and what would you test next?
Use a different value that could expose a boundary or mistake. Predict the result first, run it, and explain how the concept would help in a small real application.
Related: Previous lesson Next lesson
100 lessons across 20 modules, covering variables, operators, strings, conditions, loops, functions, scope, arrays, objects, DOM, events, state, testing, asynchronous JavaScript and application development.