Сообщение от Alexprom
|
Все равно не работает..
|
где код?
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.red {
background-color: #FF0000;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(function() {
const btn = $('div.btn'),
test = $('button.test');
test.on('click', function() {
const index = test.index(this);
btn.eq(index).toggleClass('red');
})
});
</script>
</head>
<body>
<button class="test">01 click me</button>
<button class="test">02 click me</button>
<button class="test">03 click me</button>
<button class="test">04 click me</button>
<button class="test">05 click me</button>
<div class="btn">1</div>
<div class="btn">2</div>
<div class="btn">3</div>
<div class="btn">4</div>
<div class="btn">5</div>
</body>
</html>