Skip to content

Commit f2e53f2

Browse files
committed
Project - 1 and DOM/EditRemove file is added.
1 parent 47a84bb commit f2e53f2

File tree

9 files changed

+167
-2
lines changed

9 files changed

+167
-2
lines changed

06_DOM/05_EditRemove.html

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,36 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Edit and Remove Concept in JS DOM</title>
77
</head>
8-
<body></body>
8+
<body style="background-color: #212121; color: beige">
9+
<ul class="language">
10+
<li>Javascript</li>
11+
</ul>
12+
13+
<script>
14+
//Basic way to add or create new HTML tag inside the existing one.
15+
function addNewLang(langName) {
16+
const newListItem = document.createElement('li');
17+
newListItem.innerHTML = `${langName}`;
18+
document.querySelector('.language').appendChild(newListItem);
19+
}
20+
addNewLang('Java - My Love');
21+
addNewLang('C++');
22+
23+
// The best and optimized way to to create function to add elements
24+
function addLangByOptimizedWay(langName) {
25+
const li = document.createElement('li');
26+
li.appendChild(document.createTextNode(langName))
27+
document.querySelector(".language").appendChild(li);
28+
}
29+
addLangByOptimizedWay("HTML");
30+
addLangByOptimizedWay("CSS")
31+
32+
33+
// Now how to "Edit" values?
34+
const secondLang = document.querySelector("li:nth-child(2)"); // nth-child indexing starts from zero
35+
secondLang.innerHTML = "SachinLang";
36+
secondLang.remove(); //after commenting this you can see "SachinLang"
37+
38+
</script>
39+
</body>
940
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<link rel="stylesheet" href="./styles.css" />
8+
<title>JavaScript Background Color Switcher</title>
9+
</head>
10+
<body>
11+
<div class="canvas">
12+
<!-- <a
13+
style="
14+
background-color: #fff;
15+
padding: 10px 30px;
16+
border-radius: 8px;
17+
color: #212121;
18+
text-decoration: none;
19+
border: 2px solid #212121;
20+
"
21+
href="../index.html"
22+
>Back to Home Page</a
23+
> -->
24+
<h1>Color Scheme Switcher</h1>
25+
<span class="box" id="grey"></span>
26+
<span class="box" id="pink"></span>
27+
<span class="box" id="blue"></span>
28+
<span class="box" id="yellow"></span>
29+
<h2>
30+
Try clicking on one of the colors above
31+
<span>to change the background color of this page!</span>
32+
</h2>
33+
</div>
34+
<script src="script.js"></script>
35+
</body>
36+
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Projects related to DOM
2+
3+
## Projects Link:
4+
[Click Here to get all the Projects we've made.](https://stackblitz.com/edit/dom-project-chaiaurcode?file=index.html)
5+
6+
# Solution Code
7+
8+
## Project - 1 (Basic Method)
9+
10+
```javascript
11+
console.log("Hey, there!");
12+
const boxes = document.querySelectorAll(".box");
13+
const body = document.querySelector("body");
14+
15+
boxes.forEach(function (box) {
16+
console.log(boxes);
17+
box.addEventListener('click', function (event) {
18+
console.log(event);
19+
// console.log(eventts.target);
20+
if (event.target.id === "grey") {
21+
document.body.style.backgroundColor = event.target.id;
22+
}
23+
else if (event.target.id === "pink") {
24+
document.body.style.backgroundColor = event.target.id;
25+
}
26+
else if (event.target.id === "blue") {
27+
document.body.style.backgroundColor = event.target.id;
28+
}
29+
else {
30+
document.body.style.backgroundColor = event.target.id;
31+
}
32+
});
33+
});
34+
```
35+
36+
## Project - 1 (Best/Optimized method)
37+
38+
```javascript
39+
const buttons = document.querySelectorAll(".button");
40+
const body = document.body;
41+
42+
buttons.forEach(button => {
43+
button.addEventListener('click', event => {
44+
const color = event.target.id;
45+
body.style.backgroundColor = color;
46+
});
47+
});
48+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const boxes = document.querySelectorAll(".box");
2+
const body = document.querySelector("body");
3+
4+
boxes.forEach(function (box) {
5+
console.log(boxes);
6+
box.addEventListener('click', function (event) {
7+
console.log(event);
8+
// console.log(eventts.target);
9+
if (event.target.id === "grey") {
10+
document.body.style.backgroundColor = event.target.id;
11+
}
12+
else if (event.target.id === "pink") {
13+
document.body.style.backgroundColor = event.target.id;
14+
}
15+
else if (event.target.id === "blue") {
16+
document.body.style.backgroundColor = event.target.id;
17+
}
18+
else {
19+
document.body.style.backgroundColor = event.target.id;
20+
}
21+
})
22+
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
*{
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
body{
7+
margin: 20px;
8+
/* display: flex;
9+
flex-direction: row;
10+
flex-wrap: wrap; */
11+
}
12+
13+
.box{
14+
height: 150px;
15+
width: 150px;
16+
display: inline-block;
17+
border: 2px solid wheat;
18+
}
19+
#grey{
20+
background-color: grey;
21+
}
22+
#pink{
23+
background-color: rgb(243, 185, 185);
24+
}#blue{
25+
background-color: blue;
26+
}#yellow{
27+
background-color: yellow;
28+
}

07_Projects/Project - 2 (DOM)/index.html

Whitespace-only changes.

07_Projects/Project - 2 (DOM)/script.js

Whitespace-only changes.

07_Projects/Project - 2 (DOM)/styles.css

Whitespace-only changes.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

0 commit comments

Comments
 (0)