-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfour.html
More file actions
62 lines (45 loc) · 1.53 KB
/
four.html
File metadata and controls
62 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit and Remove Element in DOM </title>
</head>
<body style="background-color: #212121;color:white">
<ul class="language">
<li>JavaScript</li>
</ul>
</body>
<script>
// Adding new list with help of DOM and function.
function addLanguage(langName){
const ul=document.querySelector('.language');
const list=document.createElement('li');
list.innerHTML=`${langName}`;
ul.appendChild(list);
}
// addLanguage("python");
// addLanguage("C++");
// *************** Optimized Method to add new list using TextNode. ****************
function OptimizedMethod(langName)
{
const li=document.createElement('li')
li.appendChild(document.createTextNode(langName)); // here it will take less time as compared to the above method.
document.querySelector('.language').appendChild(li)
}
OptimizedMethod('Ruby')
OptimizedMethod('TypeScript')
OptimizedMethod('Java')
OptimizedMethod('C#')
// Edit Element using replaceWith
function newEle(newLang){
const repEle=document.querySelector("li:nth-child(2)"); //selecting the 2nd element of the list
const newEle=document.createElement("li");
newEle.textContent=`${newLang}`
repEle.replaceWith(newEle); //replaceWithMethod
}
newEle(".NET")
//Remove
const last=document.querySelector('li:last-child'); // accessing the last element of list
last.remove()
</script>
</html>