![]() ![]() This fires when a user clicks a mouse button twice in quick succession. As you can see from the list above, mouse events can take many forms.Īnother common mouse event is dblclick, which stands for double-click. This is exactly what occurred in the previous example. The click event occurs when a user presses and releases a mouse button while its pointer is over an element. ![]() Several events use the MouseEvent interface. JavaScript has a MouseEvent interface that represents events that occur because of a user’s interaction with their mouse. Every time you click the button, you should see this output in your console. The clickDemo() function prints “Hi there” to the browser console. When the button fires that event, the listener will call the clickDemo() function. The specific event it listens for has the name “click”. ![]() It then adds an event listener to this element using the addEventListener() method. The JavaScript code above accesses the first button on the page using the querySelector() function. The app.js File document.querySelector( '.btn').addEventListener( "click", clickDemo) So, if you want to initiate a specific process whenever a user clicks the first button on the web page, this is the file to create it in. ![]() The app.js file will contain the code to set up the event listeners. The HTML code above creates a simple page that links to a JavaScript file called app.js. Let’s create the following web page that has a few HTML elements:
0 Comments
Leave a Reply. |