I am trying to determine the opacity of a simple div
using JavaScript.
Currently, I am using the following code:
var d = document.getElementById('1').style.opacity;
console.log(d); //prints nothing
However, when I check the output in the console.log
, it shows an empty line. Do I need to explicitly add the opacity property in the CSS file or is it set by default?
This is my HTML & CSS:
.room{
width:90%;
height:75px;
border-radius:3px;
text-align:center;
}
<div class="room" id="1">
//content
</div>
Any ideas on why it's returning a blank result?