+ 1

How do you put an alert on "click" of a button?

https://code.sololearn.com/WLs156zQ9Urk/?ref=app

29th Nov 2022, 1:21 PM
skaffyy
skaffyy - avatar
3 ответов
+ 2
There are at least 2 ways (see Javascript course, lesson 50) A) Put the function directly onto the html button element <button id="btn1" onclick="alert('Click 1')">Button 1</button> B) Add the function to the button via Javascript: When the DOM is completely loaded, we get the html element in Javascript and add the event listener for "click" with the function.
29th Nov 2022, 2:14 PM
Lisa
Lisa - avatar
0
But right under the button's code?
29th Nov 2022, 2:17 PM
skaffyy
skaffyy - avatar
0
https://code.sololearn.com/WZgQ7VDG70aH/?ref=app You have forgotten to add callback function to the addEventListener function
30th Nov 2022, 11:39 AM
Calviղ
Calviղ - avatar