Whenever I try to manipulate CSS in DOM and check if a CSS node has a certain value, It won't work if I actually check it against its value as assigned in my CSS file. Instead I need to first check it against a null value. The code below is an example.
var nav = document.getElementById('nav');
if(nav.style.backgroundColor == ''){
nav.style.backgroundColor = 'green';
nav.firstChild.nextSibling.style.borderBottom = '2px solid yellow';
}
The code above will execute when
nav.style.backgroundColor == '';
and not when I check it against its actual color assigned in my css file.
nav.style.backgroundColor == 'blue';
Why is that? I know that the browser will turn the HTML file into a DOM, but does it not check against css styling?
JSFiddle : http://jsfiddle.net/7AX3m/1/
Edit Found another link on SO that uses getComputedStyle()