Im having a problem with my code here. It wont display all of the colors on the div, an im fairly certain its because its trying to set and display almost 17 million colors at once. I get a google chrome error saying the error code is STATUS_BREAKPOINT upon clicking the div. Its supposed to display all the possible colors of the rgb range in a single linear gradient. I have tested the array loop, and it works fine alone, but the problem is displaying and setting all the colors simultaneously. I have tried adding a line of code that changed the animation duration, hoping that the problem was just displaying them, but it didnt work. I was wondering if there was any way I could optimize this code to run without browser errors. Here is the full code:
<div onclick="oc()" id="d">
</div>
<script>
function oc() {
var div = document.getElementById("d")
var allColors = range(0, 16777215)
div.style.background = "linear-gradient(to right," + allColors + ");"
}
function range(start, end) {
var ans = [];
for (let i = start; i <= end; i++) {
var i2 = i.toString(16)
ans.push(" #" + i2);
}
return ans;
}
</script>
<style>
#d {
width: 500px;
height: 25px;
background-color: black;
/*My attempt to stop the error below*/
animation-duration: 10s;
}
</style>