HTML Get Element by ID

getElementById() is the easiest way of referring to an HTML tag via JavaScript calls. It is used to perform various actions dynamically, on the client side, without refreshing the current page or doing server-side calls. A common use is to place it inside an onClick event trigger. Here is the example of a clickable paragraph that shows an alert window with a text.

HTML Example:

Click me!

Result:

Click me!

Use your imagination, as a homework, to come with various other uses of the getElementById() call inside an event trigger.

Share

Learn how to design amazing websites