How to access css properties in javascript when applied via external CSS file?

You can only access style properties in Javascript that have been set via Javascript (or the style attr).

To access the elements current style you should fetch the computed style of the element.

var el = document.getElementById('hello');
var comp = el.currentStyle || getComputedStyle(el, null);
alert( comp.backgroundColor );

Note, that the computed style may vary in browsers (like color being in hex or rgb) so you should normalize that if you want unified results.

Leave a Comment