+ 1
How do you put an alert on "click" of a button?
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.
0
But right under the button's code?
0
https://code.sololearn.com/WZgQ7VDG70aH/?ref=app
You have forgotten to add callback function to the addEventListener function