It seems like I am overlooking a very fundamental aspect here.
Essentially, there are 2 div elements in the HTML markup. When one is clicked (#x), the other div element (#block1) gains a new class (.change), resulting in a change in its color.
The issue lies within the selector ("#block1") used inside the click function. Substituting the id of the first div with a class works perfectly fine. However, using an id instead renders it invalid.
$(document).ready(function() {
$("#x").click(function() {
$("#block1").toggleClass("change");
});
});
#block1 {
width: 20vw;
height: 20vw;
background: gold;
margin-left: auto;
margin-right: auto;
position: relative;
}
#x {
height: 5vw;
width: 5vw;
background: #333;
position: relative;
right: -60vw;
top: -15vw;
cursor: pointer;
}
.change {
background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div id="block1"></div>
<div id="x"></div>