JavaScript
7
Вклад в тег
const arr = ['one', 'two', 'three']
let str = []
str = arr.map(a => a[0])
str = str.join(', ')
<section class="flex-sec">
<button>BTN</button>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</section>
section {
display: flex;
button {
width: 50px;
height: 50px;
border: solid 4px black;
background: yellow;
}
}
div {
width: 200px;
height: 200px;
background: #00ff0b;
margin: 10px;
}
.b1 {
background: #fc0;
}
let cards = document.querySelectorAll(".flex-sec > div");
let button = document.querySelector(".flex-sec>button");
let firstClick = true;
button.addEventListener("click", switchColor);
function switchColor() {
for (let i = 0; i < cards.length; i++) {
if (firstClick) {
if (i % 2 == 0) {
cards[i].classList.add("b1");
}
} else {
cards[i].classList.toggle("b1");
}
}
firstClick = false;
}