I was attempting to incorporate a checkbox into a Bootstrap form that turns green when it is checked. Here is the code I used:
function updateColor() {
$("#check1").animate({
"background-color": "rgb(209, 231, 221)"
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c2e2323383f383e2d3c0c79627c627c612e29382d7f">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<div class="input-group mb-3">
<span class="input-group-text"><input type="checkbox" onclick="updateColor()" id="checkbox"></span>
<input type="text" id="check1" class="form-control" placeholder="This is a checkbox">
</div>
However, upon implementation, an error appeared in the console indicating that a color was expected but instead NaNrgb
was received.
I also attempted using the hex code #d1e7dd
, but encountered another failure.
Why does JavaScript confuse this for a NaN
object? Is there a solution to rectify this issue?
Thank you in advance