Сергей Ракипов,
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>index</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="index">
<meta name="Keywords" content="index">
<style>
.blok{
width: 400px;
height: 100px;
margin: 10px auto;
display: flex;
justify-content: space-around;
}
.kvadrat{
width: 100px;
height: 100px;
border: 3px solid #000;
}
.kvadrat.aktiv{
border: 3px solid #0504aa;
}
.kvadrat:focus{
outline: none;
}
</style>
</head>
<body>
<div class="blok">
<button class="kvadrat aktiv"></button>
<button class="kvadrat"></button>
<button class="kvadrat"></button>
</div>
<div class="blok">
<button class="kvadrat aktiv"></button>
<button class="kvadrat"></button>
<button class="kvadrat"></button>
</div>
<div class="blok">
<button class="kvadrat aktiv"></button>
<button class="kvadrat"></button>
<button class="kvadrat"></button>
</div>
<script>
let body = document.body;
let aktiv = ({target}) => {
target = target.closest(".kvadrat");
if(!target) return;
let parent = target.closest(".blok");
let current = parent.querySelector(".kvadrat.aktiv");
current && current.classList.remove("aktiv");
target.classList.add("aktiv");
}
body.addEventListener("click", aktiv);
</script>
</body>
</html>