Forum Moderators: open
Essentially I have an anchored image that I want users to click to change the visibility of a div. The page loads with the div set to "visibility: hidden;", from an external and linked stylesheet set.
When the page (or any page containing this code) is first opened, two clicks are required to change the div's visibilty instead of just one. After that, toggling the visibility only takes one click.
Everything works perfectly except this one function. All the code I'm using is obtained from tutorials and free javascript sites, as I'm not competent enough to write my own stuff yet.
Here's any relevant source:
function switchvis(id){
if(document.getElementById(id)) {
var ele = document.getElementById(id);
if(ele.style.visibility=="hidden") {
ele.style.visibility="visible";
}
else {
ele.style.visibility="hidden";
}
}
}
... and the HTML:
<a href="javascript://" onclick="switchvis('remote');"><img src="img/skyremote.gif" height="30" width="112" alt="Remote Control" /></a>
Note: I dont know if the href makes a difference, I set it to "#", removed it altogether and used "javascript://", and they all appeared to have the same effect.
This appears also to be a problem that is not browser-dependant.
first of all, the a nor img has no id. but i think in your code, it has.
then, the visibility style seems to be not initialized on startup. on the first click it will be set to a value and that way initialized, and then working properly.
so if you initialize first, there will be no problem.