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

javascriptdocument.getElementById(element id);

Example

Let's get an input by its id and change the content of the value attribute:

html<input id="elem" value="???">
javascriptlet elem = document.getElementById('elem');
elem.value = '!!!';

The code execution result:

html<input id="elem" value="!!!">

See also