ixiz,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.red {
color: red;
}
.green {
color: green;
}
.blue {
color: blue;
}
.gray {
color: gray;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
const nav = document.querySelector('.nav-list');
let active, filterValue;
nav.addEventListener('click', ({ target }) => {
if (target = target.closest('[data-filter]')) {
if (active) {
active.classList.remove(filterValue)
}
active = target;
filterValue = target.dataset.filter;
active.classList.add(filterValue)
}
})
})
</script>
</head>
<body>
<ul class="nav-list">
<li data-filter="red" class="nav-list__item" id="red">Красный</li>
<li data-filter="green" class="nav-list__item" id="green">Зеленый</li>
<li data-filter="blue" class="nav-list__item" id="blue">Синий</li>
<li data-filter="gray" class="nav-list__item" id="gray">Сброс</li>
</ul>
</body>
</html>