Hmm, you have indeed got the code for switchBanner wrong! The first time the code is called, it rewrites over the whole of the content of mainBanner with the content of serviceBanner1. This [b]writes over[/i] the content of both serviceBanner1 and servicebanner2, so
they no longer exist in the document tree. Any future attempt to reference either of them is doomed to failure, because they don't exist anymore!
Sorry, I didn't even look at your switchBanner code before because I'd spotted a problem in your earlier code (and frankly I wasn't treating this like a formal code review
).
if you want to do it this way I *think* setting up the banners array outside of the function might work.
A better way to change whether you can see a DIV programatically is to set its .style.display property:
Code:
document.getElementById("serviceBanner1").style.display = "block";
document.getElementById("serviceBanner2").style.display = "none";
will turn off display of serviceBanner2 and show serviceBanner1 instead. While you've only got 2 or 3 divs to roll through this works OK: more than that and you need to look at enumerating the children of a parent (in this case your "mainBanner" div). But for now I'd play with using your c variable with an if statement and doing it manually, just to get it working: there's a few complexities and pitfalls to watch out for when enumerating the children of an element...
I'm not concerned by the lack of a class so much as putting the attribute in when you're not using it
but as you say, that'll come with time...