I am looking to change specific div colors oclick to either blue or grey - There are a number of different divs under the same class and I want to be able to click on each one individually to change the color to either blue or grey
<div class="sidebar2" onclick="change(this)">
<p>11</p>
</div>
<div class="sidebar2" onclick="change(this)">
<p>10</p>
</div>
<div class="sidebar2" onclick="change(this)">
<p>9</p>
</div>
<div class="sidebar2" onclick="change(this)">
<p>8</p>
</div>
<!-- JavaScript -->
<script>
function change(elm) {
elm.style.backgroundColor = '#1E90FF'
}
</script>
Aucun commentaire:
Enregistrer un commentaire