Skip to content

Commit 093b7d5

Browse files
committed
update advanced dom events
1 parent 958763a commit 093b7d5

22 files changed

+2519
-0
lines changed

13-Advanced-Dom-Events/.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"arrowParens": "avoid"
4+
}

13-Advanced-Dom-Events/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Advanced DOM
2+
3+
The DOM is simply a data representation of all object that comprises of the structure and content of a web document
4+
5+
Each DOM elements is called a node and it is simply an object that has various properties that can be used to manipulate or make changes to the element.
6+
7+
## NodeList
8+
9+
A `nodelist` is simply an object collection of nodes. It is usually returned by properties like `Node.childNodes` and methods like `document.querySelectorAll()`
10+
11+
### Elements that returns a NodeList:
12+
13+
- `document.querySelectorAll()`
14+
- `document.getElementByName()`
15+
16+
> Note: Nodelists are not arrays but they can be iterated using the `forEach()` method and converted to an array using `Array.from()`
17+
18+
NodeLists returned from the `document.querySelectorAll` methods are static, which means updates made to the DOM does not affect the collection.
19+
20+
## HTML Collection
21+
22+
HTMLCollection is an array-like object collection of HTML elements. It is similar to a nodeList except it is live and not static, this means it is automatically updated when changes are made to it's underlying document.
23+
24+
### Elements that returns a HTMLCollection:
25+
26+
- `document.getElementsByClassName()`
27+
- `document.getElementsByTagName()`
28+
29+
## Creating and Inserting Elements
30+
31+
Previously we looked at how to add elements in the DOM using the `.insertAdjacentHTML()` property, but there is another property that allows us even more flexibility, and this property is called the `createElement()` property.
32+
33+
- By using `document.createElement()` property:
34+
35+
```js
36+
const message = document.createElement('div');
37+
message.classList.add('cookie-message');
38+
message.textContent = 'We use cookies for improved funtionality and analytics';
39+
message.innerHTML = `We use cookies for improved functionality and analytics. <button class='btn btn--close-cookie'>Got it!</button>`;
40+
41+
header.prepend(message);
42+
```
43+
44+
`prepend` adds the element as the first child of the element the prepend is called with.
45+
`append` adds the element as the last child.
46+
`before` adds the element before the element the before is called with
47+
`after` adds the element after the element the after is called with
19.1 KB
Loading

13-Advanced-Dom-Events/img/card.jpg

2.21 MB
Loading
16.8 KB
Loading
515 KB
Loading
3.16 KB
Loading

13-Advanced-Dom-Events/img/grow.jpg

93 KB
Loading

13-Advanced-Dom-Events/img/hero.png

562 KB
Loading

13-Advanced-Dom-Events/img/icon.png

3.83 KB
Loading

13-Advanced-Dom-Events/img/icons.svg

+1,324
Loading

13-Advanced-Dom-Events/img/img-1.jpg

1.42 MB
Loading

13-Advanced-Dom-Events/img/img-2.jpg

1.1 MB
Loading

13-Advanced-Dom-Events/img/img-3.jpg

992 KB
Loading

13-Advanced-Dom-Events/img/img-4.jpg

1010 KB
Loading

13-Advanced-Dom-Events/img/logo.png

10.2 KB
Loading

13-Advanced-Dom-Events/img/user-1.jpg

4.91 KB
Loading

13-Advanced-Dom-Events/img/user-2.jpg

5.06 KB
Loading

13-Advanced-Dom-Events/img/user-3.jpg

4.73 KB
Loading

0 commit comments

Comments
 (0)