Browse Source

first-words: add code examples to create and append element

content-update
Marie Malarme 3 years ago committed by Clément
parent
commit
0873214d5e
  1. 13
      subjects/first-words/README.md

13
subjects/first-words/README.md

@ -33,6 +33,19 @@ In the JS file, like in the previous exercise, get the HTML button element with
- set its [`className`](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) to `words`, that we just added earlier in the CSS
- use the [`append`](https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append) method to add it inside the `torso` element
### Code examples
Create a new element and add it inside the body:
```js
// create a new `div` element
const div = document.createElement('div') // the argument passed (string) is the html tag
// select the `body` and add the new `div` inside it
const body = document.querySelector('body')
body.append(div)
```
### Expected output
[This](https://youtu.be/Eq9liRCc-zA) is what you should see in the browser.

Loading…
Cancel
Save