element.classList.contains(className); // CHECKS if the element has a class(classname) elements[i].classList.toggle("selected"); // toggles a class on and off in this case in a for loop var circle = document.createElement("p"); // creates an element window.addEventListener("beforeunload", function (e) { // to add function when closing the tab or being redirected var confirmationMessage = "\o/"; (e || window.event).returnValue = confirmationMessage; //Gecko + IE return confirmationMessage; //Webkit, Safari, Chrome });