I understand it is necessary to reduce the code.
Will work with the "correct" markup.
$('.button').click(function() { $('.img').eq($(this).index('.button')).addClass('active') .siblings('.img').removeClass('active') })
.active { color: blue; } span { border: 1px solid black; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="imgs"> <p class="img imgEx1 active">Лак</p> <p class="img imgEx2">Ваниль</p> <p class="img imgEx3">Мёд</p> </div> <div class="buttons"> <span class="button button1">Лак</span> <span class="button button2">Ваниль</span> <span class="button button3">Мёд</span> </div>
htmlwe can conclude - newProgrammer.toggle_active_buttonand specify a specific picture via thedata-*attribute and create a general class for yourimgEx, so as not to sort through them all manually. - Alex Krass