All quizzesEasy
DOM & Events
Preview — 3 of 10 questions
Which method is used to select an element by its ID in JavaScript?
Adocument.getElementById("id")
Bdocument.querySelector("#id")
Cdocument.querySelector(".id")
Ddocument.getElementByClass("id")
How do you change the text content of an HTML element with JavaScript?
AAll of the above
Belement.textContent = "New text";
Celement.innerText = "New text";
Delement.innerHTML = "New text";
What is the correct way to add a new class to an element?
Aelement.className = "new-class";
Belement.addClass("new-class");
Celement.class = "new-class";
Delement.classList.add("new-class");
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.