Skip to content

Commit 33b8d21

Browse files
committed
feat: 🎸 added DOM manipulation example
1 parent d89b364 commit 33b8d21

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<title>Form Validation</title>
7+
<link rel="stylesheet" href="./style.css" type="text/css" />
8+
</head>
9+
<body>
10+
<header>
11+
<h1>DOM Manipulation</h1>
12+
</header>
13+
<main></main>
14+
<script src="./script.js"></script>
15+
</body>
16+
</html>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const divElement = document.createElement('div')
2+
3+
const textContent = document.createTextNode('This is Text')
4+
divElement.appendChild(textContent)
5+
6+
// Inline styles
7+
divElement.style.border = '1px solid black'
8+
divElement.style.padding = '10px'
9+
divElement.style.display = 'flex'
10+
divElement.style.justifyContent = 'space-between'
11+
divElement.style.alignItems = 'center'
12+
divElement.style.borderRadius = '10px'
13+
14+
// Add styles via classes
15+
divElement.classList.add('container')
16+
17+
// Add div to body
18+
document.body.appendChild(divElement)
19+
20+
const crossButton = document.createElement('span')
21+
crossButton.style.backgroundColor = 'red'
22+
crossButton.style.padding = '5px 7px'
23+
crossButton.style.borderRadius = '50%'
24+
crossButton.innerHTML = 'X'
25+
crossButton.style.cursor = 'pointer'
26+
27+
// Add cursor pointer on hover of cross button
28+
crossButton.addEventListener('mouseover', () => {
29+
crossButton.style.cursor = 'pointer'
30+
})
31+
32+
divElement.appendChild(crossButton)
33+
34+
crossButton.addEventListener('click', () => {
35+
// remove div
36+
document.body.removeChild(divElement)
37+
})
38+
39+
// Remove the component
40+
setTimeout(() => {}, 1000)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.form-container {
2+
padding: 0;
3+
margin-top: 100px;
4+
width: 50%;
5+
display: flex;
6+
flex-direction: column;
7+
gap: 10px;
8+
}
9+
10+
.form-input-field {
11+
padding: 10px;
12+
border-radius: 10px;
13+
border-width: 0.5px;
14+
}
15+
16+
.submit-btn {
17+
padding: 10px;
18+
display: block;
19+
border-radius: 10px;
20+
border-width: 0.5px;
21+
cursor: pointer;
22+
}
23+
24+
.container {
25+
background-color: rgb(215, 209, 209);
26+
}

0 commit comments

Comments
 (0)