Modern JavaScript
JavaScript without libraries – selecting elements, events, changing the page, loading data with fetch, forms and storing data in the browser. The examples are verified in the Chrome, Firefox and Safari browsers (the Chromium, Gecko and WebKit engines).
Selecting page elements no longer needs jQuery. The querySelector and querySelectorAll methods use the same CSS selectors and work in all current browsers. How to use them, how to loop through the elements found and where to put the script on the page.
A click, a key press, submitting a form – JavaScript reacts to all of them through addEventListener. How to write an event handler, what the event object contains and why delegating events to a parent element pays off.
Changing text, adding a class, creating a new element – plain JavaScript handles all of it as easily as jQuery. But you need to watch the difference between textContent and innerHTML, otherwise you open the website to an XSS attack.
The fetch function replaces $.ajax from jQuery. With the async and await keywords, code that waits for the server to respond reads like ordinary code from top to bottom. How to load data in JSON, how to prepare it in PHP, how to send data to the server and which errors not to forget.
A form can be submitted in the background, without loading a new page, and the result shown to the user right away. How to do it with FormData and fetch, how to use the form validation built into the browser and how to add your own rule.
A closed notice, a chosen theme, a half-filled form – small things that a website should remember in the browser are stored in localStorage. How to work with the storage safely, how to store objects and what does not belong in it.
Most of what jQuery used to be added for, browsers now handle by themselves. An overview of the most common jQuery notations and their replacements in plain JavaScript – handy when editing older scripts.