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 > Document</ title >
7+ < style >
8+ .btn {
9+ padding : 10px 20px ;
10+ font-size : 1.1em ;
11+ color : white;
12+ background-color : # 007BFF ;
13+ border : none;
14+ }
15+ </ style >
16+ </ head >
17+ < body >
18+ < button class ="btn " > Click Me</ button >
19+ < div >
20+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint, repellendus quasi!
21+ </ div >
22+ < div class ="second ">
23+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint, repellendus quasi!
24+ </ div >
25+ < div >
26+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint, repellendus quasi!
27+ </ div >
28+ < div >
29+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint, repellendus quasi!
30+ </ div >
31+
32+ </ body >
33+ < script >
34+ //dom (Documnet object model ) ever element is an object in js
35+ //we can manipulate the element using js
36+ const btn = document . querySelector ( ".btn" ) ;
37+ // btn.addEventListener("work",function)
38+ btn . addEventListener ( "click" , handelClick ) ;
39+ function handelClick ( ) {
40+ if ( btn . textContent === "Click Me" ) {
41+ btn . style . backgroundColor = "green" ;
42+ btn . textContent = "Clicked" ;
43+ }
44+ else {
45+ btn . style . backgroundColor = "#007BFF" ;
46+ btn . textContent = "Click Me" ;
47+ }
48+
49+ }
50+ btn . addEventListener ( "mouseover" , function ( ) {
51+ if ( btn . textContent === "Clicked" ) {
52+ }
53+ else {
54+ btn . style . backgroundColor = "red" ;
55+ }
56+ } )
57+ btn . addEventListener ( "mouseout" , function ( ) {
58+ if ( btn . textContent === "Click me" ) {
59+
60+ btn . style . backgroundColor = "#007BFF" ;
61+ }
62+ } )
63+
64+
65+ //click ,hover ,mouseout ,keydown ,
66+
67+
68+
69+
70+
71+
72+ </ script >
73+
74+ </ html >
0 commit comments