getElementById()

noun

say it: “get-EL-uh-ment-by-EYE-DEE” /ɡɛt ˈɛləmənt baɪ ˌaɪ ˈdiː/

A DOM method that finds the one element with a given id.

What is getElementById() in JavaScript?

getElementById() — A method on document that finds the one element whose id matches, or returns null if there isn't one. It's the quickest way to grab a single element you gave an id.

const total = document.getElementById("cart-total");
total.textContent = "$42.00";

In a sentence

  • “I used getElementById("cart-total") to update the total on the page.”

Level: Apprentice · More JavaScript terms at this level

Updated