2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Render HTML Elements to the DOM
|
|
|
|
---
|
|
|
|
# Render HTML Elements to the DOM
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2019-01-26 20:27:19 -05:00
|
|
|
To render an element to the DOM, we use the following syntax
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
2018-10-12 15:37:13 -04:00
|
|
|
ReactDOM.render(<item to be rendered>, <where to be rendered>);
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
2019-01-26 20:27:19 -05:00
|
|
|
Use the Document method `getElementByID()` to target a specfic node in the DOM
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
2019-01-26 20:27:19 -05:00
|
|
|
document.getElementByID(<target node>)
|
2019-07-24 00:59:27 -07:00
|
|
|
```
|
2019-01-26 20:27:19 -05:00
|
|
|
Use the Document method `getElementByID()` as an argument within the ReactDOM method `render()` to solve this challenge.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-01-26 20:27:19 -05:00
|
|
|
Following the syntax, we would add this line of code to render the JSX element to the `div` with the id of challenge-node.
|
2019-07-24 00:59:27 -07:00
|
|
|
```javascript
|
|
|
|
ReactDOM.render(JSX, document.getElementById("challenge-node"));
|
|
|
|
```
|
|
|
|
</details>
|