You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please note -- if we don't store the function in a variable, then we can't remove it. There's no way to "read back" handlers assigned by `addEventListener`.
262
262
````
263
263
264
-
Multiple calls to `addEventListener` allow to add multiple handlers, like this:
264
+
Multiple calls to `addEventListener` allow it to add multiple handlers, like this:
265
265
266
266
```html run no-beautify
267
267
<inputid="elem"type="button"value="Click me"/>
@@ -288,7 +288,7 @@ As we can see in the example above, we can set handlers *both* using a DOM-prope
288
288
````warn header="For some events, handlers only work with `addEventListener`"
289
289
There exist events that can't be assigned via a DOM-property. Only with `addEventListener`.
290
290
291
-
For instance, the `DOMContentLoaded` event, that triggers when the document is loaded and DOM is built.
291
+
For instance, the `DOMContentLoaded` event, that triggers when the document is loaded and the DOM has been built.
292
292
293
293
```js
294
294
// will never run
@@ -334,10 +334,10 @@ Some properties of `event` object:
334
334
`event.currentTarget`
335
335
: Element that handled the event. That's exactly the same as `this`, unless the handler is an arrow function, or its `this` is bound to something else, then we can get the element from `event.currentTarget`.
336
336
337
-
`event.clientX / event.clientY`
337
+
`event.clientX` / `event.clientY`
338
338
: Window-relative coordinates of the cursor, for pointer events.
339
339
340
-
There are more properties. Many of them depend on the event type: keyboard events have one set of properties, pointer events - another one, we'll study them later when we come to different events in details.
340
+
There are more properties. Many of them depend on the event type: keyboard events have one set of properties, pointer events - another one, we'll study them later when as we move on to the details of different events.
341
341
342
342
````smart header="The event object is also available in HTML handlers"
343
343
If we assign a handler in HTML, we can also use the `event` object, like this:
@@ -373,7 +373,7 @@ For instance:
373
373
374
374
As we can see, when `addEventListener` receives an object as the handler, it calls `obj.handleEvent(event)` in case of an event.
375
375
376
-
We could also use a class for that:
376
+
We could also use a class (although we still have to instantiate it as an object):
0 commit comments