Web development
Web Pages, Events, and Debugging
Updated Oct 28, 2026
The DOM represents page elements as objects that JavaScript can inspect and update. Select an existing element and listen for events such as a button click. Use textContent for plain text. If somethin
What you’ll learn
Understand and practise web pages, events, and debugging.
Explanation
The DOM represents page elements as objects that JavaScript can inspect and update. Select an existing element and listen for events such as a button click. Use textContent for plain text. If something does not work, check the console, confirm the selector matches, and make sure the script runs after the element exists.
DOM តំណាងឱ្យធាតុនៅលើទំព័រ។ JavaScript អាចជ្រើសធាតុ និងឆ្លើយតបពេលចុចប៊ូតុង។ ប្រសិនបើមិនដំណើរការ សូមពិនិត្យ console និង selector។
Example
const button = document.querySelector("#hello"); button.addEventListener("click", () => { button.textContent = "Hello!"; });
Practice
What should you check if document.querySelector returns null?
Answer and explanation
Show answer / បង្ហាញចម្លើយ
Confirm an element with the selector exists and the script runs after it has been created.
Quick recap
The DOM represents page elements as objects that JavaScript can inspect and update.