Skip to content

Commit a8693aa

Browse files
committed
edit and remove in dom
1 parent 98c78a2 commit a8693aa

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

06_DOM/one.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Chai aur code | DOM</title>
8+
</head>
9+
<body style="background-color: #212121; color: #fff;">
10+
<ul class="language">
11+
<li>Javascript</li>
12+
</ul>
13+
</body>
14+
<script>
15+
function addLanguage(langName){
16+
const li = document.createElement('li');
17+
li.innerHTML = `${langName}`
18+
document.querySelector('.language').appendChild(li)
19+
}
20+
addLanguage("python")
21+
addLanguage("typescript")
22+
23+
function addOptiLanguage(langName){
24+
const li = document.createElement('li');
25+
li.appendChild(document.createTextNode(langName))
26+
document.querySelector('.language').appendChild(li)
27+
}
28+
addOptiLanguage('golang')
29+
30+
//Edit
31+
const secondLang = document.querySelector("li:nth-child(2)")
32+
console.log(secondLang);
33+
//secondLang.innerHTML = "Mojo"
34+
const newli = document.createElement('li')
35+
newli.textContent = "Mojo"
36+
secondLang.replaceWith(newli)
37+
38+
//edit
39+
const firstLang = document.querySelector("li:first-child")
40+
firstLang.outerHTML = '<li>TypeScript</li>'
41+
42+
//remove
43+
const lastLang = document.querySelector('li:last-child')
44+
lastLang.remove()
45+
46+
47+
</script>
48+
</html>

0 commit comments

Comments
 (0)