Skip to content

Commit 8095b48

Browse files
committed
fixed #90
1 parent 6b8fdf3 commit 8095b48

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

2-ui/2-events/04-default-browser-action/article.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ The object will catch any right-click, look through stored handlers and run the
201201
But then each piece of code that wants a context menu should know about that object and use its help instead of the own `contextmenu` handler.
202202
```
203203

204-
205204
## Summary
206205

207206
There are many default browser actions:
@@ -219,3 +218,13 @@ All the default actions can be prevented if we want to handle the event exclusiv
219218
To prevent a default action -- use either `event.preventDefault()` or `return false`. The second method works only for handlers assigned with `on<event>`.
220219

221220
If the default action was prevented, the value of `event.defaultPrevented` becomes `true`, otherwise it's `false`.
221+
222+
```warn header="Stay semantic, don't abuse"
223+
Technically, by preventing default actions and adding JavaScript we can customize the behavior of any elements. For instance, we can make a link `<a>` work like a button, and a button `<button>` behave as a link (redirect to another URL or so).
224+
225+
But we should generally keep the semantic meaning of HTML elements. For instance, `<a>` should preform navigation, not a button.
226+
227+
Besides being "just a good thing", that makes your HTML better in terms of accessibility.
228+
229+
Also if we consider the example with `<a>`, then please note: a browser allows to open such links in a new window (by right-clicking them and other means). And people like that. But if we make a button behave as a link using JavaScript and even look like a link using CSS, then `<a>`-specific browser features still won't work for it.
230+
```

0 commit comments

Comments
 (0)