Trusted answers to developer questions

What is the getElementByID method() in JavaScript?

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

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.

RELATED TAGS

javascript
html
getelementbyid
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?