Skip to content

Commit 3aee882

Browse files
committed
Js DOM BOM Events
1 parent 8441d82 commit 3aee882

21 files changed

+1317
-0
lines changed

Events And Other DOM Properties.js

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
// console.log(document.getElementsByTagName('span')[0])
2+
// console.dir(document.getElementsByTagName('span')[0]) // -> Span Ko Object Dikhayega With Its Properties
3+
4+
// console.log -> Shows the element DOM tree
5+
// console.dir -> Shows the element as an object with its properties
6+
7+
// console.log(document.body.firstChild.nodeName)
8+
// console.log(document.body.firstElementChild.nodeName)
9+
10+
// TagName/ NodeName
11+
// TagName -> Only Exists For Element Nodes
12+
// NodeName -> Defined For Any Node (Text, Comment, etc)
13+
14+
// innerHTML / outerHTML
15+
// innerHTML -> The Inner HTML Property allows to get the HTML inside the element as a string. -> Work For Element Nodes Only
16+
17+
// outerHTML -> The outerHTML property contains the full HTML. -> Work For All Nodes
18+
19+
// outerHTML Property Contain The Full HTML innerHTML + The Element Itself
20+
// first.innerHtml -> Help In Get Or Set The Inner HTML
21+
// first.innerHtml = "<i>Hey I Am Italic</i>" -> Insertion
22+
23+
// first.outerHTML -> Help In Get Or Set The Outer HTML
24+
// Output -> <span id="first"><i>Hey I Am Italic</i></span>
25+
26+
27+
// document.body.firstChild.data -> Gives The Data Of The First Child
28+
// document.body.firstChild.nodeValue -> Same As Data
29+
30+
// Text Content
31+
// The textContent property allows to get the text inside the element as a string. Only Works For Element Nodes
32+
33+
// console.log(document.body.textContent)
34+
35+
// Hidden Property
36+
// The hidden attribute and the DOM property specifies whether the element is visible or not.
37+
// first.hidden = false -> Shows The Element
38+
// first.hidden = true -> Hides The Element
39+
40+
// Attributes Method
41+
// 1. elem.hasAttribute(name) -> Method To Check For Existence Of An Attribute
42+
// 2. elem.getAttribute(name) -> Method Used To Get The Value Of An Attribute
43+
// 3. elem.setAttribute(name, value) -> Method Used To Set The Value Of An Attribute
44+
// 4. elem.removeAttribute(name) -> Method Used To Remove The Attribute From Element
45+
// 5. elem.attributes -> Method To Get The Collection Of All Attributes
46+
// Data-* Attributes
47+
// We Can Always Create Custom Attributes But The One Starting With "data-" Are Reserved For Programmer Use. They Are Available In A Property Named dataset
48+
// If An Element Has An Attribute Named "data-one" -> The Way To Access This Attribute Is : elem.dataset.one
49+
50+
51+
// let a = first.getAttribute("class")
52+
// console.log(a)
53+
54+
55+
// console.log(first.hasAttribute("class"))
56+
// console.log(first.hasAttribute("style"))
57+
// // first.setAttribute("hidden", "true")
58+
// first.setAttribute("class", "true sachin")
59+
// first.removeAttribute("class")
60+
// console.log(first.attributes)
61+
// console.log(first.dataset)
62+
// console.log(first.dataset.game)
63+
// console.log(first.dataset.player)
64+
65+
66+
// Always Add Custom Attribute With Data-_____
67+
// Data Attributes
68+
// data-one = "one" -> data-one -> One
69+
// data-game = "mario" -> data-game -> Mario
70+
71+
// If Element Has A Attribute Named "data-one" -> The Way To Access This Attribute Is : elem.dataset.one
72+
73+
// Insertion Method
74+
75+
// There Are Three Way To Insert HTML Into The DOM
76+
77+
// 1. innerHTML
78+
79+
// let a = document.getElementsByTagName('div')[0]
80+
// a.innerHTML = a.innerHTML + '<h1>Hello World!</h1>';
81+
82+
83+
// 2. document.createElement()
84+
// let div = document.createElement('div');
85+
// div.innerHTML = '<h1>Hello World!</h1>';
86+
// a.appendChild(div);
87+
// div.className = "alert"
88+
// We Can Use For Loop In This Case
89+
90+
// 3. document.createTextNode()
91+
// let div = document.createTextNode('This Is Text Node');
92+
// a.appendChild(div);
93+
94+
// Node Insertion Method
95+
// 4. node.append(e) -> Append At The End Of Node
96+
97+
// 5. node.prepend() -> Insert At The Beginning Of Node
98+
99+
// 6. node.before() -> Insert Before Node
100+
101+
// 7. node.after() -> Insert After Node
102+
103+
// 8. node.replaceWith() -> Replace Node With Another Node
104+
105+
// Insert Adjacent HTML / Text / Element
106+
107+
// first.insertAdjacentHTML('beforebegin', '<div class="test">beforebegin</div>');
108+
// first.insertAdjacentHTML('beforeend', '<div class="test">beforeend</div>');
109+
// first.insertAdjacentHTML('afterbegin', '<div class="test">afterbegin</div>');
110+
// first.insertAdjacentHTML('afterend', '<div class="test">afterend</div>');
111+
112+
// Node Removal
113+
// first.remove() -> Remove The Element
114+
115+
116+
// ClassName & ClassList
117+
// className -> Used To Add/Remove/Toggle A Class
118+
// classList -> Used To Add/Remove/Toggle A Class
119+
first.className = "text-black red"
120+
first.classList.remove("red") // Remove Karva
121+
first.classList.add("red") // Add Karva
122+
first.classList.toggle("red") // He To Hata Dega Nahi He to Laga Dega
123+
first.classList.contains("red") // Check If Contain Or Not? -> True False
124+
125+
// SetTimeout And SetInterval
126+
127+
// setTimeout(function, <delay>, <arg1>, <arg2>)
128+
// setTimeOut -> Kuch Time Ke Bad Apni JS Ko excute Karna Hoga -> Excute The Js After Certain Time
129+
// clearTimeout -> To Clear The SetTimeout
130+
// setInterval -> In Certain Interval Of Time Hame Bar Bar Apni Js Ko Excute Karna Hoga -> Excute The Js After Certain Time(Interval)
131+
// setTimeout -> Is Function Ko Run Kardo Itne Time Ke Bad
132+
133+
// alert("Hello")
134+
// let a = setTimeout(function() {
135+
// alert("I Am Inside Of SetTimeout")
136+
// }, 2000)
137+
// clearTimeout(a)
138+
// console.log(a) // Timer Id
139+
140+
// let timerId = setInterval(function, <delay>, <arg1>, <arg2>)
141+
// Delay In millisecond
142+
// Timer Id Return Me Milti He
143+
144+
// const sum = (a, b, c) => (){
145+
// console.log("Yes I Am Running " + (a + b + c))
146+
// a + b
147+
// }
148+
149+
// setTimeout(sum, 1000, 1, 2, 7)
150+
// clearTimeout(timerId)
151+
152+
// setInterval -> Bar Bar Kuch Time Ke Bad Run Karna
153+
// Syntex -> setInterval(function, <delay>, <arg1>, <arg2>)
154+
155+
// Example:
156+
// let a = setInterval(function() {
157+
// console.log("I Am In SetInterval")
158+
// }, 3000)
159+
160+
161+
// clearInterval(a) -> To Clear The SetInterval
162+
163+
// Browser Events
164+
// An Event Is A Signal That Something Has Happened.
165+
// All Dom Node Generate Such Signal
166+
167+
// Mouse Events -> click, contextmenu, mouseover/mouseout, mousedown/mouseup, mousemove
168+
169+
// Keyboard Events -> keydown and keyup
170+
// Form Element Events -> submit, focus
171+
// Document Events -> DOMContentLoaded
172+
173+
// <button onclick = "alert('hello')">Click Me</button>
174+
175+
// Handling Events
176+
// elem.onclick = function(e){
177+
// alert("Hello World1!")
178+
// }
179+
180+
// let a= document.getElementsByClassName("container")[0]
181+
// a.onclick = () =>{
182+
// let b = document.getElementsByClassName("container")[0]
183+
// b.innerHTML = "Hello World!"
184+
// }
185+
186+
// If Onclick Js and HTML Me Likha Hai To Js Vala Priorty Hota Hai
187+
188+
// Adding A Handler With JavaScript Overwrite The Existing Handler
189+
190+
// Event Listener
191+
192+
// addEventListener(event, handler) and removeEventListener(event, handler)
193+
194+
// addeventListener -> To Assign Multiple Handlers To An Event
195+
1.2 MB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

0 commit comments

Comments
 (0)