HTML DOM Flashcards
get the element with ID “demo” and change its text to “Hello!”
document.getElementById(“demo”).innerHTML = “Hello!”;
get the first paragraph tag and change its text to “Hello!”
document.getElementsByTagName(“p”)[0].innerHTML = “Hello!”;
Change the text of the first element that has the class name “test” to “Hello!”.
document.getElementsByClassName(“test”)[0].innerHTML = “Hello!”;
get the first image with Id “hero” and change its src attribute to “bob.png”
document.getElementByID(“hero”).src = “bob.png”;
get the input field with Id “greeting” and change its value to “hello!”
document.getElementById(“greeting”).value = “Hello!”;
get the element with Id “demo” and change its text color to red.
document.getElementById(“demo”).style.color = “red”;
get the element with Id “demo” and change its font size to 40 pixels.
document.getElementById(“demo”).style.fontSize = “40px”;
get the element with Id “demo” and hide it
document.getElementById(“demo”).style.display = “none”;
get the element wth Id “demo” and add an event listener that calls myFunction when clicked
document.getElementById(“demo”).addEventListener(“click”, myFunction);