Perhaps a duplicate question, but cannot find the answer.
element.style.display is not what is displayed in the browser.
Instead of returning the actual value (e.g. block or inline, etc.), it returns empty. Tested on Chrome 56.0.2924.87 (64-bit).
How to get the actual displayed value?
function displayStyle(aEvent) { aEvent.target.textContent=aEvent.target.style.display; } window.onload = function() { var top_array = document.getElementsByClassName("top"); for(var i = 0; i < top_array.length; i++) { top_array[i].addEventListener("click", displayStyle, false); } }
.top{ background-color:#FFF8DC; }
<div class="top">top (click it and it will disappear because its style.display is empty)</div>
J.Joe source share