# 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.

```javascript
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](https://www.ask-codey.com/glossary?category=javascript&level=2)

Updated: October 28, 2026

Source: https://www.ask-codey.com/glossary/getelementbyid
