I have a multiple buttons that need to change class on-click. I've managed to piece together some working code but wondering if there's a more efficient way of doing this? Open to all languages and solutions.
Also, is there any benefit of wrapping the (document).ready around the (document).on?
$(document).ready(function() {
$(document).on('click', '.a', function() {
$('.a').addClass('b');
$('.a').removeClass('a');
});
$(document).on('click', '.b', function() {
$('.b').addClass('c');
$('.b').removeClass('b');
});
});
div {
width: 60%;
padding: 10px 20px;
}
.a {
background: #bbb;
}
.b {
background: orange;
}
.c {
background: lightblue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="a">a</div>
<br>
<div class="a">a</div>