The console dev tools in any browser is a developer’s bestfriend for doing quick DOM changes and debugging.
Table of Contents
Lessons Learned
<input />
<p></p>
const input = document.querySelector('input')
KeyboardEvent.shiftKey
A boolean value that indicates if the
input.addEventListener('keydown', (e) => console.log(e.shiftKey))
MouseEvent.shiftKey
A boolean value that indicates whether the
The code below logs true
if we click the input
while pressing down on the
input.addEventListener('mousedown', (e) => console.log(e.shiftKey))
GlobalEventHandlers.onkeydown
This fires when the user presses a keyboard key. onkeypress
and keypress
are deprecated versions of this.
const logs = document.querySelector('p')
input.addEventListener('keydown', (e) => logs.textContent = e.code)
References
- “GlobalEventHandlers.onkeydown - Web APIs | MDN.” MDN Web Docs, Mozilla Developer Network, 5 Nov. 2021, <
developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onkeydown
>. - “Hold Shift to Check Multiple Checkboxes” wesbos.com, uploaded by Wes Bos, 8 Dec. 2016, <
javascript30.com
>. - “KeyboardEvent.shiftKey - Web APIs | MDN.” MDN Web Docs, Mozilla Developer Network, 15 Sept. 2021, <
developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/shiftKey
>. - “MouseEvent.shiftKey - Web APIs | MDN.” MDN Web Docs, Mozilla Developer Network, 15 Sept. 2021, <
developer.mozilla.org/en-US/docs/Web/API/MouseEvent/shiftKey
>.