getElementById method
The getElementById method
allows you to get a page element by its
id
attribute. With the resulting element,
it will be possible to perform various
manipulations: change its text,
attributes, CSS styles, and so on.
Syntax
document.getElementById(element id);
Example
Let's get an
input
by its id and change the content of
the value
attribute:
<input id="elem" value="???">
let elem = document.getElementById('elem');
elem.value = '!!!';
The code execution result:
<input id="elem" value="!!!">
See also
-
the
querySelectormethod
that gets element by a selector -
the
querySelectorAllmethod
that gets a group of elements by a selector