Trusted answers to developer questions

What is JavaScript rendering?

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

Javascript uses the document object model (DOM) to manipulate the DOM elements. Rendering refers to showing the output in the browser.

The DOM establishes parent-child relationships, and adjacent sibling relationships, among the various elements in the HTML file.


Code

An example of an HTML file and its corresponding DOM is shown below:

<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph</p>
<p id="demo"></p>
</body>
</html>
svg viewer

Implementation

We can use Javascript to access and even change these DOM elements, hence, altering the output on the screen. The getElementById method and the innerHTML property are particularly useful for accessing and changing these elements.


Example

The following example demonstrates how Javascript alters the contents of the DOM using these methods when an action is performed.

Explanation

In the above code, we have added Javascript code to the onclick property of the button. When the user presses the button, the Javascript code finds an element with the id = demo in the DOM and alters the contents of this element.

RELATED TAGS

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