0

I've been trying to get a fade in and out for a background image for a site, and I have been trying to get the background color of a div into a variable, this is what I've tried:

 elem = document.getElementById('nav');
 bgColor = elem.style.backgroundColor;

But once I try to alert the variable bgColor like: alert(bgColor) all I get alerted is empty in the text box. I've looked around on some Stack questions and I've tried everything that is told there and it doesn't seem to put the physical color into a variable.

1

1 Answer 1

0

window.getComputedStyle is the solution. Otherwise you'll get the "direct" styles that are empty.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.