tezvyn:

How do you select by ID and class, and what is returned?

Source: developer.mozilla.orgbeginner

This tests basic DOM API knowledge and awareness of live collections. Use document.getElementById for IDs and document.getElementsByClassName for classes, which returns a live HTMLCollection. A red flag is calling the result a static Array or NodeList.

This question tests whether you know the core Document selection methods and understand the difference between live and static collections. For an ID, use document.getElementById, which returns a single Element or null. For a class, use document.getElementsByClassName, which returns a live HTMLCollection that updates automatically when the DOM changes. A red flag is confusing the returned HTMLCollection with a NodeList or a true Array, or not knowing that it is live and can mutate during iteration.

Read the original → developer.mozilla.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

How do you select by ID and class, and what is returned? · Tezvyn