I've been experimenting with creating a fade in and out effect for a background image on a website. I've also been attempting to capture the background color of a div and store it in a variable. Here's what I have tried:
elem = document.getElementById('nav');
bgColor = elem.style.backgroundColor;
However, when I try to display the bgColor
variable using alert(bgColor)
, all that appears is an empty text box. Despite researching various Stack Overflow questions and trying multiple solutions suggested, I haven't been successful in capturing the actual color in a variable.