What is the getElementByID method() in JavaScript?

The getElementById() is a JavaScript function that lets you grab an HTML element, by its id, and perform an action on it. The name of the id is passed as a parameter, and ​the corresponding element is the return value.

svg viewer

The following code shows how the function can be used. The color of the box, with the content id, ​changes once the action button is clicked.

Copyright ©2024 Educative, Inc. All rights reserved