![Kleine orangene Raute 🔸](https://abs.twimg.com/emoji/v2/72x72/1f538.png)
![Kleine orangene Raute 🔸](https://abs.twimg.com/emoji/v2/72x72/1f538.png)
![Thread 🧵](https://abs.twimg.com/emoji/v2/72x72/1f9f5.png)
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Thread 🧵](https://abs.twimg.com/emoji/v2/72x72/1f9f5.png)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
DOM stands for Document Object Model
MDN says it is "an object-oriented representation of a webpage" which can be modified with JavaScript. All html elements are represented as objects on which methods & properties can be used to add an action or change their content/style.
MDN says it is "an object-oriented representation of a webpage" which can be modified with JavaScript. All html elements are represented as objects on which methods & properties can be used to add an action or change their content/style.
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Tastenkappe Ziffer 1 1⃣](https://abs.twimg.com/emoji/v2/72x72/31-20e3.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Kleine blaue Raute 🔹](https://abs.twimg.com/emoji/v2/72x72/1f539.png)
![Kleine blaue Raute 🔹](https://abs.twimg.com/emoji/v2/72x72/1f539.png)
elements which belongs to HTMLCollection interface
meaning all the changes in the document are reflected
automatically.
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
(NodeList is not an array but we can iterate over it using
forEach() method)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
Inside the () of querySelector and querySelectorAll specify the id with prefix "hash" and class with "period". We can also use any other CSS Selector also.
Below code specifies the above ways of selecting an element & their output.![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
Below code specifies the above ways of selecting an element & their output.
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Tastenkappe Ziffer 2 2⃣](https://abs.twimg.com/emoji/v2/72x72/32-20e3.png)
change the style by using
![Rückhand Zeigefinger nach rechts 👉](https://abs.twimg.com/emoji/v2/72x72/1f449.png)
(where element means any of the above ways used to select an element)
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Tastenkappe Ziffer 3 3⃣](https://abs.twimg.com/emoji/v2/72x72/33-20e3.png)
We can specify what action to perform after a particular event occurs like a button is clicked.
There are two ways
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
method
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Kleine blaue Raute 🔹](https://abs.twimg.com/emoji/v2/72x72/1f539.png)
attributes like onclick , onmouseover to which JS function or code can be added which specifies what needs to be done after that event occurs.
Below I have used "onclick" to change background-color to a div to blue
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Kleine blaue Raute 🔹](https://abs.twimg.com/emoji/v2/72x72/1f539.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Rückhand Zeigefinger nach rechts 👉](https://abs.twimg.com/emoji/v2/72x72/1f449.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Rückhand Zeigefinger nach rechts 👉](https://abs.twimg.com/emoji/v2/72x72/1f449.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Rückhand Zeigefinger nach rechts 👉](https://abs.twimg.com/emoji/v2/72x72/1f449.png)
(false is for event bubbling & true for event capturing)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
What is Event Propagation![Rotes Fragezeichen-Symbol ❓](https://abs.twimg.com/emoji/v2/72x72/2753.png)
way of defining the event flow
Event Flow -> the element order when an event occurs.
used when elements are nested inside other elements to specify which element's event should be handled first if event occurs on the inner element.
![Rotes Fragezeichen-Symbol ❓](https://abs.twimg.com/emoji/v2/72x72/2753.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Weißes kleines Quadrat ▫️](https://abs.twimg.com/emoji/v2/72x72/25ab.png)
![Schwarzes kleines Quadrat ▪️](https://abs.twimg.com/emoji/v2/72x72/25aa.png)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
Two types![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
Event Capturing : events of outer elements is handled
first then the inner elements.
Event bubbling : events of inner elements is handled
first then the outer elements.
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Kleine orangene Raute 🔸](https://abs.twimg.com/emoji/v2/72x72/1f538.png)
first then the inner elements.
![Kleine orangene Raute 🔸](https://abs.twimg.com/emoji/v2/72x72/1f538.png)
first then the outer elements.
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
Suppose a <p> tag in inside a <div> tag.
Then with Event Bubbling , event of <p> is handled first then comes <div>. But with Event Capturing , event of <div> is handled first and then comes <p>.
Note: Default is Event Bubbling for browsers.
Then with Event Bubbling , event of <p> is handled first then comes <div>. But with Event Capturing , event of <div> is handled first and then comes <p>.
Note: Default is Event Bubbling for browsers.
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Tastenkappe Ziffer 4 4⃣](https://abs.twimg.com/emoji/v2/72x72/34-20e3.png)
document.createElement() is used to create an HTML Element & appendChild() method is used append it.
Below code creates a p tag & appends it
to the body tag
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
![Tastenkappe Ziffer 5 5⃣](https://abs.twimg.com/emoji/v2/72x72/35-20e3.png)
Use the remove() method to remove an HTML Element from web page.
Below code creates a p tag ,sets its text ,appends it to the web page and then after 2s removes it
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Pfeil nach unten ⬇️](https://abs.twimg.com/emoji/v2/72x72/2b07.png)
DOM Manipulation is a vast topic with which we can do so many things on a web page. Adding everything to a thread would be difficult so I listed the main things I feel one needs to get started with it.
Thank you for reading!!
I hope my thread was helpful.
Thank you for reading!!
I hope my thread was helpful.
![Grinsendes Gesicht 😀](https://abs.twimg.com/emoji/v2/72x72/1f600.png)