There are 3 identical boxes with the same classes and a button:
function changeColorAndAddPadding() {
/* ??? */
}
.box {
border: 1px solid;
display: inline;
}
<button onclick="changeColorAndAddPadding();">Click Here</button>
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
I am looking to apply styles to the class .box
when the button is clicked, without adding a new class to the boxes. Essentially, upon clicking the button, I want the .box
class to have a red background color and padding, which should also be applied to all elements with this class. Is there an efficient way in JavaScript to achieve this?
Thank you in advance.