Originally designed for adding small amounts of interactivity to a page (like hovers and animations - you know the kind of thing), JavaScript is now used for almost anything up to large applications and games, and can even be found in servers. You can also see the target which is a reference to the node that was clicked.While, generally speaking, HTML is for content and CSS is for presentation, JavaScript is for interactivity. There are lots of properties giving you an idea of where the event occurred on the page (like pageX and offsetY) - these are slightly different because they depend on the reference point used to measure from. Here’s an example event you might see into a click event callback like handleClick. The second is the callback function - here it’s handleClick. Here’s it’s click - that’s a click of the mouse or a tap of the finger. The first argument is a string - the name of the event to listen for. Here it’s being called on an element saved in the button variable. Var button = document.querySelector('#big-button') īutton.addEventListener('click', handleClick) ĪddEventListener is a method found on all DOM elements. Here’s a group of the things needed to listen for an event the callback function, an element and the call to listen for an event: To react to an event you listen for it and supply a function which will be called by the browser when the event occurs. Events occur when the page loads, when user interacts (clicks, hovers, changes) and myriad other times, and can be triggered manually too. In the browser most code is event-driven and writing interactive applications in JavaScript is often about waiting for and reacting to events, to alter the behavior of the browser in some way.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |