You can use the following code snippet to change the color of an element based on its background color:
943 chars37 linesIn this code, we get the current background color of the element using window.getComputedStyle(). We then use a function to determine if the background color is dark or light, and choose a contrasting color accordingly. Finally, we use myDiv.style.color to change the text color of the element.
gistlibby LogSnag