Skip to content

Commit 140310b

Browse files
committed
EDit and Remove elements in DOM
1 parent 410a301 commit 140310b

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

06_DOM/four.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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>Chai aur code | DOM</title>
7+
</head>
8+
<body style="background-color: #212121; color: aliceblue;">
9+
<ul class= "language">
10+
<li>Javascript</li>
11+
</ul>
12+
</body>
13+
<script>
14+
function addLanguage(langNAme){
15+
const li = document.createElement('li')
16+
li.innerHTML = `${langNAme}`
17+
document.querySelector('.language').appendChild(li)
18+
}
19+
addLanguage("python");
20+
addLanguage("typeScript");
21+
22+
function addOptiLanguage(langNAme){
23+
const li = document.createElement('li');
24+
li.appendChild(document.createTextNode(langNAme));
25+
document.querySelector('.language').appendChild(li);
26+
}
27+
addOptiLanguage('golang');
28+
29+
//EDIT
30+
const secondLang = document.querySelector("li:nth-child(2)")
31+
console.log(secondLang);
32+
//secondLang.innerHTML = "MOJo"
33+
const newli = document.createElement('li')
34+
newli.textContent = "Mojo"
35+
secondLang.replaceWith(newli);
36+
37+
//edit
38+
const firstLang = document.querySelector("li:first-child")
39+
firstLang.outerHtml = '<li>TypeScript</li>'
40+
41+
//remove
42+
const lastLang = document.querySelector('li:last-child')
43+
lastLang.remove()
44+
</script>
45+
</html>

0 commit comments

Comments
 (0)