File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Event in Js</ title >
7+ < link rel ="stylesheet " href ="style.css "/>
8+ </ head >
9+ < body >
10+ < button onclick ="console.log('button was click');alert('hello') "> click me !</ button >
11+ < button ondblclick ="console.log('button was click 2 times'); "> click me 2 times !</ button >
12+ < div onmouseover ="console.log('you are inside the box') "> this is div box</ div >
13+ < button id ="btn1 "> click btn1..!</ button >
14+ < button id ="btn2 "> click btn2..!</ button >
15+
16+ < div1 > This is Box 2</ div1 >
17+
18+ < script src ="scripts.js "> </ script >
19+ </ body >
20+
21+ </ html >
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Practice Event in Js</ title >
7+ < link rel ="stylesheet " href ="style.css "/>
8+ </ head >
9+ < body >
10+ < button id ="mode "> Change Mode</ button >
11+
12+ < p > Welcome Change mode Event Listner</ p >
13+
14+ < script src ="practice.js "> </ script >
15+ </ body >
16+ </ html >
Original file line number Diff line number Diff line change 1+ let modeBtn = document . querySelector ( "#mode" ) ;
2+ let body = document . querySelector ( "body" ) ;
3+ let curmode = "light" //black
4+
5+ modeBtn . addEventListener ( "click" , ( ) => {
6+ if ( curmode === "light" ) {
7+ curmode = "dark" ;
8+ body . classList . add ( "dark" ) ;
9+ body . classList . remove ( "light" ) ;
10+ } else {
11+ curmode = "light" ;
12+ body . classList . add ( "light" ) ;
13+ body . classList . remove ( "dark" ) ;
14+ }
15+ console . log ( curmode ) ;
16+
17+ } )
18+
Original file line number Diff line number Diff line change 1+ let btn1 = document . querySelector ( "#btn1" ) ;
2+ btn1 . onclick = ( ) => {
3+ console . log ( "btn1 was clicked" ) ;
4+ let a = 25 ;
5+ a ++ ;
6+ console . log ( a ) ;
7+ }
8+
9+ let div1 = document . querySelector ( "div1" ) ;
10+
11+ div1 . onmouseover = ( ) => {
12+
13+ console . log ( "You are inside box 2" ) ;
14+
15+
16+ }
17+
18+
19+ //let btn2=document.querySelector("#btn2");
20+ //btn2.onclick=(evt)=>{
21+ // console.log(evt);//event object
22+ // console.log(evt.type);
23+ // console.log(evt.target);
24+
25+
26+ //}
27+
28+ btn2 . addEventListener ( "click" , ( ) => {
29+ console . log ( "Button 2 was clicked - 1" ) ;
30+
31+ } ) ;
32+
33+ btn2 . addEventListener ( "click" , ( ) => {
34+ console . log ( "Button 2 was clicked - 2" ) ;
35+
36+ } ) ;
37+
38+ const hand3 = ( ) => {
39+ console . log ( "Button 2 was clicked - 3" ) ;
40+
41+ } ;
42+
43+ btn2 . addEventListener ( "click" , hand3 ) ;
44+ btn2 . removeEventListener ( "click" , hand3 ) ;
Original file line number Diff line number Diff line change 1+ .dark {
2+ background-color : black;
3+ color : white;
4+ }
5+
6+
7+ .light {
8+ background-color : white;
9+ color : black;
10+ }
You can’t perform that action at this time.
0 commit comments