Fixed a bug (#25139)
There was no event argument passed but used one which was causing error. Passed event argument from `DOM`.
This commit is contained in:
@ -44,11 +44,11 @@ In the above example, when a user clicks on the `paragraph` element in the `html
|
|||||||
However if we attach `onclick` to links (HTML's `a` tag) we might want prevent default action to occur:
|
However if we attach `onclick` to links (HTML's `a` tag) we might want prevent default action to occur:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
<a href="https://guide.freecodecamp.org" onclick="myAlert()">Guides</a>
|
<a href="https://guide.freecodecamp.org" onclick="myAlert(event)">Guides</a>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function myAlert(event) {
|
function myAlert(e) {
|
||||||
event.preventDefault();
|
e.preventDefault();
|
||||||
alert("Link was clicked but page was not open");
|
alert("Link was clicked but page was not open");
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user