File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed
Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 1+ // event object argument e, evt
2+ // info about triggered event
3+ // event.type
4+ // event.currentTarget
5+ // this keyword
6+ // preventDefault() - prevents default behaviour
7+
8+ const heading = document . querySelector ( 'h1' ) ;
9+ const btn = document . querySelector ( '.btn' ) ;
10+ const link = document . querySelector ( '#link' ) ;
11+
12+ heading . addEventListener ( 'click' , function ( e ) {
13+ e . currentTarget . classList . add ( 'blue' ) ;
14+ } ) ;
15+
16+ btn . addEventListener ( 'click' , function ( e ) {
17+ e . currentTarget . classList . add ( 'red' ) ;
18+ // for check type event listener
19+ console . log ( e . type ) ; //click
20+ } ) ;
21+
22+ // // callback as reference
23+ function callink ( e ) {
24+ // //will undefined and if link click not back again to top
25+ console . log ( e . preventDefault ( ) ) ;
26+ }
27+
28+ link . addEventListener ( 'click' , callink ) ;
Original file line number Diff line number Diff line change 3030 font-size : 1.25rem ;
3131 text-transform : uppercase;
3232 }
33+
34+ a {
35+ display : inline-block;
36+ margin-top : 100vh ;
37+ }
3338 </ style >
3439 </ head >
3540 < body >
@@ -147,9 +152,13 @@ <h3>The Pirates</h3>
147152 <button class="btn">Join</button>
148153 </div> -->
149154
150- <!-- key events -->
151- < input type ="text " class ="inputName " />
155+ <!-- key events
156+ <input type="text" class="inputName" /> -->
152157
158+ <!-- even object -->
159+ < button class ="btn "> click me</ button >
160+ < h1 > some heading</ h1 >
161+ < a href ="# " id ="link "> random link</ a >
153162 <!-- source js -->
154163 <!-- <script src="/01_getElementById.js"></script> -->
155164 <!-- <script src="/02_getElementByTagName.js"></script> -->
@@ -169,6 +178,7 @@ <h3>The Pirates</h3>
169178 <!-- <script src="/16_innerHTML_textContent.js"></script> -->
170179 <!-- <script src="/17.addEventListener.js"></script> -->
171180 <!-- <script src="/18_function_reference.js"></script> -->
172- < script src ="/19_key_events.js "> </ script >
181+ <!-- <script src="/19_key_events.js"></script> -->
182+ < script src ="/20_event_object.js "> </ script >
173183 </ body >
174184</ html >
You can’t perform that action at this time.
0 commit comments