Script Valley
JavaScript in the Browser: DOM, Events & APIs
Understanding the DOM/Assessment

Practice & Assessment

Test your understanding of Understanding the DOM

Multiple Choice Questions

5
1

Which method returns null when no element matches the given CSS selector?

2

What does document.querySelectorAll('li') return?

3

You want to safely insert user-supplied text into an element without risking XSS. Which property should you use?

4

Which traversal method walks up the DOM tree and returns the nearest ancestor matching a CSS selector?

5

Why should you use a DocumentFragment when inserting many elements at once?

Coding Challenges

1
1

Dynamic Task List Builder

Given an HTML page with an input field (#task-input), an Add button (#add-btn), and an empty unordered list (#task-list): write JavaScript so that clicking Add creates a new <li> with the input's text and a Remove button. Clicking Remove deletes only that <li>. Input: any text string from the field. Output: the li appears in the list; clicking its remove button deletes it. Constraint: use createElement and textContent only โ€” no innerHTML. Estimated time: 20-25 minutes.

Easy

Mini Project

1

Live Character-Count Bio Editor

Build a bio editor using only vanilla DOM APIs. Requirements: a textarea (#bio), a live character counter (#char-count) that updates on every keystroke showing remaining characters out of a 200-character limit, a preview div (#preview) that mirrors the textarea content as plain text in real time, a Save button (#save-btn) that appends the current bio as a new card element to a #history list with a timestamp, and a Clear button (#clear-btn) that removes all history cards. Use createElement, textContent, dataset, and DOM traversal โ€” no innerHTML, no libraries.

Easy
Practice & Assessment โ€” Understanding the DOM โ€” JavaScript in the Browser: DOM, Events & APIs โ€” Script Valley โ€” Script Valley