I am unfamiliar with JavaScript, but I wish to utilize a function to alter the background color of multiple cards.
function ChangeColorToGreen() {
document.getElementById("ChangingCard").style.background = "green";
}
function ChangeColorToPurple() {
document.getElementById("ChangingCard").style.background = "purple";
}
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f1d10100b0c0b0d1e0f3f4a514f514d">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c1e1313080f080e1d0c3c49524c524e">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<div class="container">
<div class="container-fluid">
<div class="row mt-3">
<!-- Card -->
<div class="ChangingCard" id="ChangingCard">
<div class="dropdown col-sm">
<a class="dsh253" href="#" role="button" id="ChangeColorCardBG" data-bs-toggle="dropdown" aria-expanded="false">
BackgroundColor
</a>
<ul class="dropdown-menu dsh250" aria-labelledby="ChangeColorCardBG">
<div class="dshcd250">
<li><a class="dropdown-item" onclick="ChangeColorToGreen();">Green</a></li>
<li><a class="dropdown-item" onclick="ChangeColorToPurple();">Purple</a></li>
</div>
</ul>
</div>
<h4><b>02 / Employee Workgroup / Apartment</b></h4>
<p>Sorting the same employee workgroups into the same <i>apartments</i> / Houses 2022-06-27 in progress</p>
</div>
<!-- end card -->
<!-- ---------------------------------------------------------- -->
<!-- Card -->
<div class="ChangingCard" id="ChangingCard">
<div class="dropdown col-sm">
<a class="dsh253" href="#" role="button" id="ChangeColorCardBG" data-bs-toggle="dropdown" aria-expanded="false">
BackgroundColor
</a>
<ul class="dropdown-menu dsh250" aria-labelledby="ChangeColorCardBG">
<div class="dshcd250">
<li><a class="dropdown-item" onclick="ChangeColorToGreen();">Green</a></li>
<li><a class="dropdown-item" onclick="ChangeColorToPurple();">Purple</a></li>
</div>
</ul>
</div>
<h4><b>02 / Employee Workgroup / Apartment</b></h4>
<p>Sorting the same employee workgroups into the same <i>apartments</i> / Houses 2022-06-27 in progress</p>
</div>
<!-- end Card -->
</div>
</div>
</div>
I have imported the cards from phpMyAdmin
, and I desire each card to possess the ability to change the background color. When I click the BackgroundColor
button, the background color only changes on the first card. Is there a solution for a JavaScript code to function for all the cards as displayed in the code above?