See code below:
$(".btn").on("click", function(){
$(".main-div").toggleClass("active");
});
.main-div.active {
background: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="one">
<div class="btn">ClickMe1</div>
<div class="main-div">Div1</div>
</div>
<div class="one">
<div class="btn">ClickMe2</div>
<div class="main-div">Div2</div>
</div>
Hi guys, can you help me with this matter? Well my goal is to when I click the first button it should only add class on the first
.main-divhowever, by using toggle it adds also on the second div. Can anyone help me how to implement it correctly?