Skip to content

Day 3 of 40 days of JavaScript #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 123 commits into
base: day-03
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
999864f
Merge pull request #5 from tapascript/day-03
atapas Feb 18, 2025
d93a747
(feat) Day 04 code and assignments
atapas Feb 20, 2025
a8cda36
day 05 changes
atapas Feb 23, 2025
503ebd6
Merge pull request #6 from tapascript/day-05
atapas Feb 23, 2025
7a3df0e
fix: typo
Refayth Feb 24, 2025
140edf0
Merge pull request #7 from Refayth/main
atapas Feb 25, 2025
013d9a4
(feat) Day 06 lesson
atapas Feb 26, 2025
2e6cfd4
bug fixes
atapas Feb 26, 2025
5aad8ca
Merge pull request #8 from tapascript/day-06
atapas Feb 26, 2025
c3cb7c9
Update README.md
atapas Feb 26, 2025
00ca37f
Update README.md
atapas Feb 26, 2025
7980924
Update README.md
atapas Feb 28, 2025
4602022
Update task.md
atapas Mar 1, 2025
07582b8
(feat) Day 07 projects
atapas Mar 1, 2025
15a30a5
Merge remote-tracking branch 'origin/main' into day-07
atapas Mar 1, 2025
e9fdb1e
(day 07) Updated readme
atapas Mar 1, 2025
18e403c
Merge pull request #9 from tapascript/day-07
atapas Mar 2, 2025
c2ba27d
(feat) Day 08
atapas Mar 4, 2025
e9f5380
Merge pull request #10 from tapascript/day-08
atapas Mar 4, 2025
7bca5d4
(feat) Day 09
atapas Mar 6, 2025
d53ccad
Merge pull request #11 from tapascript/day-09
atapas Mar 6, 2025
b03f92b
(fix) readme
atapas Mar 6, 2025
84c5f37
Merge pull request #12 from tapascript/day-09
atapas Mar 6, 2025
c55b690
(feat) Day 10 code and readme
atapas Mar 10, 2025
68b4c4a
(feat) day 10 - Tasks added
atapas Mar 10, 2025
133eb4e
Merge pull request #13 from tapascript/day-10
atapas Mar 10, 2025
40537d8
(feat) Day 11 Closure Done
atapas Mar 12, 2025
6b9c7d3
Merge pull request #14 from tapascript/day-11
atapas Mar 12, 2025
ef2e9d1
(feat) Day 12 done
atapas Mar 16, 2025
3ba9148
Merge pull request #15 from tapascript/day-12
atapas Mar 16, 2025
ed43d8c
Update index.js
atapas Mar 18, 2025
3e9202a
(feat) Day 13 this keyword
atapas Mar 19, 2025
7f80858
Merge pull request #16 from tapascript/day-13
atapas Mar 19, 2025
46a7863
day 14 code
atapas Mar 23, 2025
ac751c0
(feat) Live 01 code
atapas Mar 24, 2025
a2f90db
(feat) Live 01
atapas Mar 24, 2025
eb1acad
Merge pull request #17 from tapascript/live-01
atapas Mar 24, 2025
ee1a26f
Merge remote-tracking branch 'origin' into day-14
atapas Mar 24, 2025
12872c0
(feat) Added Day 14 Exception handling
atapas Mar 24, 2025
c144eb5
Merge pull request #18 from tapascript/day-14
atapas Mar 25, 2025
44494e7
(feat) Day 15 Array Course - Initial Commits
atapas Mar 27, 2025
76d2522
(day 15) Array Master course
atapas Mar 30, 2025
0b74f2c
Merge pull request #19 from tapascript/day-15
atapas Mar 30, 2025
9c91bf6
(day 15) checked
atapas Mar 30, 2025
8d8178a
Merge pull request #20 from tapascript/day-15
atapas Mar 30, 2025
c3af822
(day 15) updated readme
atapas Mar 30, 2025
7a0457d
Merge pull request #21 from tapascript/day-15
atapas Mar 30, 2025
c481cf4
(feat) Day 16 JavaScript Debugging
atapas Apr 2, 2025
a72d070
Merge pull request #22 from tapascript/day-16
atapas Apr 2, 2025
e94d8c2
(day 17) Introduction to DM
atapas Apr 3, 2025
59764c1
(project) Project assignment of module 2
atapas Apr 3, 2025
5ea325d
Merge remote-tracking branch 'origin/main' into day-17
atapas Apr 3, 2025
96136d2
Update task.md
atapas Apr 5, 2025
cc6d0ad
(Day 18) DOM Manipulations
atapas Apr 6, 2025
a66e21d
Merge remote-tracking branch 'origin/main' into day-18
atapas Apr 6, 2025
0054258
Merge pull request #23 from tapascript/day-17
atapas Apr 6, 2025
0f7eb8a
Merge remote-tracking branch 'origin/main' into day-18
atapas Apr 6, 2025
81c5370
Update README.md
atapas Apr 6, 2025
d222d48
Merge pull request #24 from tapascript/day-17
atapas Apr 6, 2025
2670689
(day 18) readme fixes
atapas Apr 7, 2025
5904d37
Update task.md
atapas Apr 8, 2025
19d483a
(day 19) JavaScript Events
atapas Apr 8, 2025
0e119bc
(day 18) DOM Manipulations
atapas Apr 8, 2025
02ddbb5
Merge branch 'day-18' into day-19
atapas Apr 8, 2025
a3581b2
(day 19) DOM Events
atapas Apr 8, 2025
e1b95d1
Merge pull request #25 from tapascript/day-18
atapas Apr 13, 2025
3a57b94
Merge pull request #26 from tapascript/day-19
atapas Apr 13, 2025
01f4cd0
(feat) Day 20 Advanced DOM
atapas Apr 16, 2025
ae7c03e
Merge remote-tracking branch 'origin/main' into day-20
atapas Apr 16, 2025
941177f
(feat) Day 20 - Added Tasks
atapas Apr 16, 2025
fa16453
Merge pull request #27 from tapascript/day-20
atapas Apr 16, 2025
a9ba600
(feat) day 21 - DOM Project
atapas Apr 28, 2025
9e3cfe3
Merge pull request #28 from tapascript/day-21
atapas Apr 28, 2025
d69ee00
(fix) day 21 link fix
atapas Apr 28, 2025
5cd2ddb
Merge pull request #29 from tapascript/day-21
atapas Apr 28, 2025
3ba265b
(feat) Day 22 - API Routes for PizzaHub
atapas Apr 29, 2025
fa6dc4d
(feat) Day 22 - Added the order POST api
atapas Apr 29, 2025
9574ba1
(feat) Day 22 - code doc
atapas Apr 30, 2025
e0548da
(feat) Day 22 - Code Committed
atapas Apr 30, 2025
337d5dd
(feat) Day 22 - Readme update
atapas Apr 30, 2025
ce00e58
(feat) Day 22 - Readme Update
atapas May 1, 2025
a581ab9
Merge pull request #30 from tapascript/day-22
atapas May 1, 2025
47c3d32
(feat) Day 23 - Added the promise example
atapas May 2, 2025
b455e4f
(fix) Day 23 - Refactor
atapas May 2, 2025
bb18d8b
(feat) Day 23 - Added delay
atapas May 2, 2025
19cd197
(feat) Day 23 - All updates
atapas May 3, 2025
0a3fa89
Merge pull request #31 from tapascript/day-23
atapas May 3, 2025
34f9cc4
(fix) Day 23 - fixed alignment
atapas May 3, 2025
12ef7ba
Merge pull request #32 from tapascript/day-23
atapas May 3, 2025
32d4837
(feat) Day 24 - pizzahub example
atapas May 5, 2025
b6e1953
(feat) Day 24 - async/await session
atapas May 7, 2025
1454c5e
Merge pull request #33 from tapascript/day-24
atapas May 7, 2025
87b63d6
Create LICENSE
atapas May 8, 2025
8932429
(feat) Day 25 - The fetch() API
atapas May 12, 2025
5a0c64e
(feat) day 25 - The fetch() API
atapas May 15, 2025
92893f7
(fix) Day 25 - fixed comments
atapas May 15, 2025
f92fb8d
(fix) Day 25 - comment fix
atapas May 15, 2025
f1dc916
Merge pull request #34 from tapascript/day-25
atapas May 15, 2025
9ec5fa2
(feat) Day 26 - Common Mistakes
atapas May 19, 2025
27a7cf8
Merge pull request #35 from tapascript/day-26
atapas May 19, 2025
c83f450
(feat) Day 27 Event Loop
atapas May 22, 2025
591f01f
(feat) LIVE LET's Code
atapas May 25, 2025
ad342fd
Merge pull request #37 from tapascript/live-lets-code
atapas May 25, 2025
74299c9
added live readme
atapas May 25, 2025
ada05f0
Merge pull request #36 from tapascript/day-27
atapas May 25, 2025
3a87bb6
Merge pull request #38 from tapascript/live-lets-code
atapas May 25, 2025
f797e47
Added inventory API
atapas May 25, 2025
972362d
Merge pull request #39 from tapascript/live-lets-code
atapas May 25, 2025
3c9f920
(feat) DAY 28 - Added country Explorer
atapas May 25, 2025
8351bf6
(feat) Day 28 - Country Project
atapas May 27, 2025
c321bca
Merge pull request #40 from tapascript/day-28
atapas May 27, 2025
5d38242
(feat) OOP Concept
atapas Jun 1, 2025
a766c7f
Merge pull request #41 from tapascript/day-29
atapas Jun 1, 2025
e5fa507
(feat) Day 30 - ES6 Classes
atapas Jun 5, 2025
3a21f82
Merge pull request #42 from tapascript/day-30
atapas Jun 6, 2025
d83f067
(feat) day 31 - Prototype and Prototype Chain
atapas Jun 7, 2025
fc63718
Merge pull request #43 from tapascript/day-31
atapas Jun 7, 2025
accb3b3
(feat) JavaScript Modules done
atapas Jun 10, 2025
b5c8f71
(feat) main readme update
atapas Jun 10, 2025
b8686e5
Merge pull request #44 from tapascript/day-32
atapas Jun 10, 2025
2ac569d
(feat) Day 33 Collections and Day 10 task bugfix
atapas Jun 12, 2025
4dd13dd
Merge pull request #45 from tapascript/day-33
atapas Jun 12, 2025
b281435
The above are the outcome of my assignment for 40
Pishon-P Jun 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ I am an independent educator and open-source enthusiast who creates meaningful p
- **`Day 17: Introduction to JavaScript DOM`** - [Watch Video](https://youtu.be/F4mVSaj6uls) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-17/README.md)
- **`Day 18: DOM Manipulations and Project`** - [Watch Video](https://www.youtube.com/watch?v=BoYgn_Mf0hA) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-18/README.md)
- **`Day 19: Master JavaScript Events Like a PRO`** - [Watch Video](https://youtu.be/ybgI5vVE668) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-19/README.md)
- **`Day 20: Advanced DOM Tips and Tricks`** - [Watch Video](https://youtu.be/aNhPav1DgTY) || [Source Code](https://github.com/tapascript/40-days-of-javascript/blob/main/day-20/README.md)
36 changes: 36 additions & 0 deletions day-20/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Day 20 - 40 Days of JavaScript - Advanced DOM Tips and Tricks

## **🎯 Goal of This Lesson**

- ✅ Intro
- ✅ Efficient DOM Travarsal
- ✅ Template and Cloning
- ✅ Document Fragment
- ✅ Range
- ✅ Shadow DOM
- ✅ Advanced Class Manipulations
- ✅ Handling Large-Scale Updates
- ✅ Mutation Observer

## 🫶 Support

Your support means a lot.

- Please SUBSCRIBE to [tapaScript YouTube Channel](https://youtube.com/tapasadhikary) if not done already. A Big Thank You!
- Liked my work? It takes months of hard work to create quality content and present it to you. You can show your support to me with a STAR(⭐) to this repository.

> Many Thanks to all the `Stargazers` who have supported this project with stars(⭐)

### 🤝 Sponsor My Work

I am an independent educator and open-source enthusiast who creates meaningful projects to teach programming on my YouTube Channel. **You can support my work by [Sponsoring me on GitHub](https://github.com/sponsors/atapas) or [Buy Me a Cofee](https://buymeacoffee.com/tapasadhikary)**.

## Video

Here is the video for you to go through and learn:

[![day-20](./banner.png)](https://youtu.be/aNhPav1DgTY "Video")

## **👩‍💻 🧑‍💻 Assignment Tasks**

Please find the task assignments in the [Task File](./task.md).
Binary file added day-20/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions day-20/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM - Advanced</title>
<script defer src="./index.js"></script>
</head>

<body>
<h1>Day 20 - DOM Advanced Tips</h1>

<div class="card">
<div></div>
<div></div>
</div>

<template id="card-template">
<div class="card">
<h2 class="title"></h2>
<p class="desc"></p>
</div>
</template>

<ul id="list"></ul>

<p id="para">Hello <strong>world</strong> and universe!</p>

<div class="card">
<h2>Title</h2>
<p>Description here</p>
</div>

<div id="box"></div>

<button class="btn">Some Button</button>

<div id="watchMe">Hello</div>
<button onclick="changeDOM()">Change DOM</button>

</body>

</html>
121 changes: 121 additions & 0 deletions day-20/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
console.log("Day 20 - DOM: Advanced Tips");

// Efficient DOM traversal
const parent = document.querySelector('.card');
const firstChild = parent.firstElementChild;
const next = firstChild.nextElementSibling;
const lastChild = parent.lastElementChild;
const parentOfElement = firstChild.parentElement;

// Templates and Cloning
const template = document.getElementById('card-template');
const clone = template.content.cloneNode(true);
clone.querySelector('.title').textContent = "DOM Advance Topic";
clone.querySelector('.desc').textContent = "Hope you are learning something New";

document.body.appendChild(clone);

// Document Fragment and Range

// Document Fragment
// - Not part of the main DOM tree until you insert it
// - Acts like a temp container
// - Great for building chunks of DOM before adding them.

const fragment = document.createDocumentFragment();

for (let i = 0; i<=3; i++) {
const li = document.createElement('li');
li.textContent = `Item ${i}`;
fragment.appendChild(li);
}

document.getElementById("list").appendChild(fragment);

// Range
const p = document.getElementById('para');

const range = document.createRange();

range.setStart(p.firstChild, 6); // After "Hello "
range.setEnd(p.childNodes[2], 4)

const content = range.cloneContents();

console.log(content);

// Shadow DOM
document.querySelector('.card').innerHTML

// shadow host

const shadowHost = document.querySelector('#box');
const shadow = shadowHost.attachShadow({mode: 'open'});
shadow.innerHTML = `<style>p { color: red; }</style><p>Hello Shadow!</p>`;

// Advanced Class Manipulation

const btn = document.querySelector('.btn');
btn.classList.add('active');
btn.classList.remove('disabled');
btn.classList.toggle('visible');
btn.classList.replace('error', 'success');

// Handling Large-Scale DOM Updates

function addItems(count) {
const frag = document.createDocumentFragment();
for (let i = 0; i < count; i++) {
const div = document.createElement('div');
div.textContent = `Item ${i}`;
frag.appendChild(div);
}
document.body.appendChild(frag);
}

addItems(10);

// Mutation Observer

// const observer = new MutationObserver(callback);
// observer.observe(targetNode, config);

const target = document.getElementById('watchMe');

const observer = new MutationObserver((mutationsList, observer) => {
for (const mutation of mutationsList) {
console.log(`Type of mutation: ${mutation.type}`);

if (mutation.type === 'childList') {
console.log('A child node was added or removed.');
}

if (mutation.type === 'attributes') {
console.log(`Attribute ${mutation.attributeName} was changed.`);
}

if (mutation.type === 'characterData') {
console.log(`Text content changed to: ${mutation.target.data}`);
}
}
});

const config = {
subtree: true,
characterData: true,
childList: true,
attributes: true,
}

observer.observe(target, config);

function changeDOM() {
target.textContent = "Goodbye!";
target.setAttribute("data-status", "Changed");
}






36 changes: 36 additions & 0 deletions day-20/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Tasks

Please complete the following tasks and post them on the tapaScript Discord under "40 Days of JavaScript".

> **DO NOT USE AI to FIND ANSWERS**. If you are stuck, let's discuss it on DISCORD and learn. Also, please note that none of the answers need you to create any UI. Just focus on the logic building and print the output on the browser console.

## 1. Traverse and Toggle Classes

Build a navigation menu. On click of a list item:

- Traverse up to parent `<ul>`
- Remove .active class from all `<li>`
- Add .active only to the clicked `<li>`

## 2. Highlight Text Using Range

Use the Range API to highlight a portion of a paragraph by wrapping it with a `<mark>` tag.

## 3. Use DocumentFragment for Performance

Insert 100 list items into the DOM using:

- Plain DOM methods (one by one)
- DocumentFragment (all at once)

## 4. Build a “Smart Cloner”

Create a UI with an element and a “Clone” button. Use cloneNode(true) and cloneNode(false) and show the difference visually.

## 5. MutationObserver Watcher

Create a div and use MutationObserver to log whenever:

- A new child is added
- The class attribute changes
- Text is modified