-
Notifications
You must be signed in to change notification settings - Fork 0
/
DOM.js
48 lines (32 loc) · 1.01 KB
/
DOM.js
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
let className = document.getElementsByClassName("content");
console.log(className);
console.log(className[0].innerHTML);
//Changing inner HTML
//className[0].innerHTML = "<h1> hi content is changed </h1>";
let tag = className[0].getElementsByTagName("h2");
//console.log(tag);
let timeout;
function changeInnerHTML(tag) {
tag.innerHTML = " Hey, i have changed inner HTML";
}
let id = document.getElementById("intro");
console.log(id);
//setting and changing HTML attributes
id.setAttribute("alt", "hello");
//id.textContent = "changed content";
// function timeoutFun() {
// timeout = setTimeout(changeInnerHTML(tag[0]), 500000);
// }
// timeoutFun();
//Changing CSS
id.setAttribute("style", "color: red");
id.style.color = "green";
id.style.backgroundColor = "yellow";
//ADDING ELEMENTS IN HTML
let newA = document.createElement("a");
className[0].appendChild(newA);
newA.innerHTML = " Link 6";
newA.setAttribute("href", "a");
newA.setAttribute("class", "link-6");
//REMOVE ELEMENTS
className[0].removeChild(newA);