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…
createElement makes a detached element. Set its text and attributes, then insert it with append. Creating an element alone does not make it visible. append accepts nodes and strings, while appendChild expects a node. This approach makes data flow explicit and lets you avoid constructing HTML strings for ordinary user-facing text. createElement makes a detached element; append inserts it into a parent. The two operations have different roles.
const item = document.createElement('li');
item.textContent = 'Learn DOM';
document.querySelector('#list').append(item);Run the preview tests; inspect the live page.
createElement makes a detached element. Set its text and attributes, then insert it with append. Creating an element alone does not make it visible. append accepts nodes and strings, while appendChild expects a node. This approach makes data flow explicit and lets you avoid constructing HTML strings for ordinary user-facing text.
const item = document.createElement('li');Declare item with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
item.textContent = 'Learn DOM';Read or update literal text in the selected element. It does not parse user input as HTML.
document.querySelector('#list').append(item);Execute this statement at this point in the program. Follow its arguments and returned value using the surrounding concept explanation.
const item = document.createElement('li');
item.textContent = 'Learn DOM';
document.querySelector('#list').append(item);
console.log(document.querySelectorAll("*").length);Interact with the preview; the diagnostic displays its actual element count.
createElement makes a detached element. Set its text and attributes, then insert it with append. Creating an element alone does not make it visible. append accepts nodes and strings, while appendChild expects a node. This approach makes data flow explicit and lets you avoid constructing HTML strings for ordinary user-facing text. createElement makes a detached element; append inserts it into a parent. The two operations have different roles. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
const item = document.createElement('li');Declare item with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
item.textContent = 'Learn DOM';Read or update literal text in the selected element. It does not parse user input as HTML.
document.querySelector('#list').append(item);Execute this statement at this point in the program. Follow its arguments and returned value using the surrounding concept explanation.
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.
const item = document.createElement('li');
item.textContent = 'Learn DOM';
document.querySelector('#list').append(item);
console.log(document.querySelectorAll("button").length);Interact with the preview; the diagnostic displays its actual element count.
createElement makes a detached element. Set its text and attributes, then insert it with append. Creating an element alone does not make it visible. append accepts nodes and strings, while appendChild expects a node. This approach makes data flow explicit and lets you avoid constructing HTML strings for ordinary user-facing text. createElement makes a detached element; append inserts it into a parent. The two operations have different roles. The final diagnostic counts actual matching elements. Read querySelectorAll as a selection and length as the collection count.
const item = document.createElement('li');Declare item with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
item.textContent = 'Learn DOM';Read or update literal text in the selected element. It does not parse user input as HTML.
document.querySelector('#list').append(item);Execute this statement at this point in the program. Follow its arguments and returned value using the surrounding concept explanation.
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.
Create one li containing Learn DOM and append it to #list.
// Create one li containing Learn DOM and append it to #list. // Write your JavaScript below.
const item = document.createElement('li');
item.textContent = 'Learn DOM';
document.querySelector('#list').append(item);Create, set text, then append.
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.