From 0873214d5e8c3b2496f136a2cb7f1afdd22e6dc3 Mon Sep 17 00:00:00 2001 From: Marie Malarme Date: Mon, 8 Mar 2021 12:30:21 +0000 Subject: [PATCH] first-words: add code examples to create and append element --- subjects/first-words/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/subjects/first-words/README.md b/subjects/first-words/README.md index 853ec79b..ea24ebc5 100644 --- a/subjects/first-words/README.md +++ b/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.