WEB CHEATSHEET 1

In this series, we bring you a list of useful snippets that can come handy when you are doing a web design project. They are not organized in any specific order, but they can nevertheless serve you as a good memory refresher or a set of codes that can quicken your programming.

Adding highlights on the clicked elements

var examplesAll = document.querySelectorAll(".example");for (i = 0; i < examplesAll.length; i++) {examplesAll[i].addEventListener("click", function () {this.classList.add("add-highlight");});};

Making an element invisible by adding a class:

1. In CSS we add a specific class that makes the element invisible:.is-hidden{
display: none;
}
2. In jS, we target a desired element and add that class to it:var ex1 = document.querySelector("#ex1");
ex1.classList.add("is-hidden");

Adding an Interval

setTimeout(function () {console.log("CODE");},
4000);

--

--