Skip to content

Instantly share code, notes, and snippets.

View vanaf1979's full-sized avatar

VA79 vanaf1979

View GitHub Profile
element.classList.toggle("classname");
const box = document.querySelector(".box");
const removeButton = document.querySelector('#removeClass');
removeButton.addEventListener('click', () => {
box.classList.remove("active");
});
element.classList.remove("classname");
element.classList.add("classname");
const box = document.querySelector(".box");
const addButton = document.querySelector('#setStyles');
addButton.addEventListener('click', () => {
box.classList.add("active");
});
.box {
width: 200px;
height: 150px;
background-color: hsl(222, 99%, 38%);
transition: all 0.2s ease-out;
}
.box.active {
background-color: hsl(222, 99%, 58%);
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Using css variables to change color in a specific section</title>
<link rel="stylesheet" href="./styles.css">
</head>
ul {
padding-left: 0;
list-style-position: inside;
}
ul {
padding-left: 0;
background-color: lightblue;
}
ul {
padding-left: 1.4rem;
}