I am facing an issue with having 2 identical IDs inside 2 separate sections. When the button is clicked, I want it to select the ID within this section and apply a style, then also select the ID in the other section and apply that same style.
The code snippet provided below only works for the first section. Can someone please help me out?
$( document ).ready(function() {
$('#clickMe').click(function() {
$('#square').css('background-color', 'red');
})
});
.block {width: 100%; padding-bottom: 40px;}
#square {width: 80px; height: 30px; border: 1px solid gray}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="block">
This is block 1
<button id="clickMe">Click Me</button>
<div id="square"></div>
</div>
<div class="block">
This is block 2
<div id="square"></div>
</div>