-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (55 loc) · 2.28 KB
/
script.js
File metadata and controls
65 lines (55 loc) · 2.28 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
63
64
65
alert("helloo")
//window object is by default created by browser,it is a global object with lots of methods
//dom is an subobject of window which has complete html in it
console.log("hello")
window.console.log("heiiu")
console.log(document)//shows html code
console.dir(window.document)//shows method and properties of document
//dom is. atree like structure window-documen-html-head-body where these are nodes and dom is created when web page is loaded
console.log(document.body);
console.dir(document.body)
console.log(document.body.childNodes[0])
console.dir(document.body.childNodes[0])
//helps to dynamically change the properties of web page
document.body.childNodes[1].innerText = "abcd"//put it on console and it will dynamicaly chnage it until refreshed
//script tag is written after body tag as it will not be able to access its dom if written in head tag
let heading = document.getElementById("heading")
console.log(heading)
console.dir(heading)
heading.innerText = "new heading"
heading.innerHTML ="<i>new heading</i>"
let para = document.getElementsByClassName("paragraph")//return collection array
console.log(para)
console.dir(para)
let p = document.getElementsByTagName("p")
console.log(p)
console.dir(p)
let query = document.querySelector(".hellooo")//return first element having this id/class/tag
console.log(query)
let q = document.querySelectorAll(".hellooo")//return all element
let s = document.querySelector("#paragraph")
console.log(query.tagName)//returns tag
//parent child sibling
console.log(document.querySelector("div").children)//provide all the children of div
let d = document.querySelector("ul");
console.log(d.innerText)
console.log(d.innerHTML)
//d.innerText="uhkuh"
let px = document.querySelector("h5");
console.log(px.textContent)//shows the hidden content;
let x = document.querySelector("#object");
console.log(x.getAttribute("id"))//tel u the name of attribute;
x.setAttribute("class","new_class")//changes the attribute name;
console.log(x.style)
x.style.backgroundColor = "yellow";
x.style.fontSize = "20px";
//x.innerText = "namsaste"
newbtn = document.createElement("button")
x.innerText = "plz click";
console.log(newbtn)
let y = document.querySelector(".create");
y.append(newbtn)//inside
y.prepend(newbtn)
y.before(newbtn)//outside
y.after(newbtn)
y.remove();