My code works fine in firefox but in Chrome I get an error. It’s just grabbing an element and setting the opacity so I’m not sure where I’m going wrong.
var bot = document.getElementById ("bot");
var top = document.getElementById ("top");
top.style.opacity = 0.0;
I get the error “Uncaught TypeError: Cannot set property ‘opacity’ of undefined” for the third line of code and I’m not sure what the problem is. I’ve checked to make sure that the element’s id is ‘top’ and that it’s the only element with that id.
This is the relevant html code
<div class = "banner" id = "bot">
<div class = "bannerTop" id = "top">
</div>
</div>
Any help would be appreciated.
Change the name of your global variable to something other than
topand it works in Chrome:http://jsfiddle.net/jfriend00/y2QQT/
This is likely because
window.topus a read-only variable that already exists.You could also put your code into a local function so your var
topisn’t a global variable and it should also work then as shown here: http://jsfiddle.net/jfriend00/62uYa/.