Javascript – keyboard events

Javascript – keyboard events

List with keyboard events keydown – triggered when a key is pressed keyup – triggered when a key is released keypress (deprecated) – triggered when a key pressed and releaded List with keyboard event properties keycode – returns the Unicode code key – returns the pressed key in string format code – returns the pressed key in string format. It is totally independent of the keyboard layout shiftkey – returns if Shift key is pressed ctrlkey – returns if Ctrl key is pressed altkey – returns if Alt key is…

Javascript – keyboard events Read More

Javascript – the event object

Javascript – the event object

When a listener ‘s event occurs, it passes an argument to the function that is associated with the listener. This argument is a reference to the event object which contains some properties. Below is a small list with common properties and methods for all the event types event.type – the type of event occurred (click, moveup etc) event.target – the element that the event occurred to. event.preventDefault() – prevents the execution of the default behaviour of the browser (showing the context menu when right-clicking) event.stopPropagation() – prevents the event listener…

Javascript – the event object Read More

Javascript – Events

Javascript – Events

You can execute javascript code when an event occurs. To happen this you need to add an event listener. You can add an event listener in Javascript or to an HTML element. Let’s see adding an event listener to an HTML element. Now, in Javascript, you need to get the reference for the button. Now, add the event listener You can also write the callback function as an anonymous function Another method to add the event listener is to add it in HTML using attributes: You can remove an event…

Javascript – Events Read More