I’m attempting to find the css display value while iterating through an unordered list (), but for some reason FF doesn’t display this value. Here’s what I have so far:
var LIs = document.getElementById('ulABC').getElementsByTagName('li');
for (var i=0; i<LIs.length; i++) {
alert('the li display value is :'+LIs[i].style.display+':');
}
All I get is a blank response. Any thoughts?
The value of
LIs[i].style.displaymirrors exactly what is set in thestyleattribute. It does not reflect anything the browser got from stylesheets. To get these computed values, usewindow.getComputedStyle().This link shows the jQuery implementation of their
.css()property, which does exactly this. Note, that on IE below IE 9 you need to use a method nameddocument.documentElement.currentStyle(), hence theif..elseclause.