Forum Moderators: open
<a href="#blue1" onclick="document.getElementById('blue1').className='event_visible'; return false;">
<a name="blue1"></a>
<div class="event" id="blue1" name="blue1">
(stuff)
</div>
CSS:
div.event{
margin-top:20px;
visibility:hidden;
display:none;
}
div.event_visible{
display:block;
visibility:visible;
}
I am trying to get a div to appear when a user clicks on a link. Only the IE group (both 6 and 7) fail to make the class change if the user clicks the link.
On the other hand, the link to make all hidden divs appear does work:
function displayAllEvents(){
var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) {
var div = divs[i];
if (div.className.indexOf('event') == 0 && div.className) {
div.className = 'event_visible';
}
}
}
I'm at a loss and it's driving me crazy. Could someone give me a nudge in the right direction? I have done forum and web searches but no solutions seem to work.
I also had to remove the "return false;" from the onclick because it stopped Firefox from jumping down the page to the newly opened div.
So now I have
<a href="#blue1" onclick="document.getElementById('blue1').className='event_visible';"><a name="blue1"></a>
<div class="event" id="blue1">
(stuff)
</div>
Internet Explorer still will not open the div.
I decided to try and paste the css, div, and javascript link it its own plain html page to see if for some reason another style was causing a problem, and IE still won't change the class. Now I have just this on a plain html page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style type="text/css">
div.event{
margin-top:20px;
visibility:hidden;
display:none;
}div.event_visible{
display:block;
visibility:visible;
}
</style>
</head>
<body>
<a href="#blue1" onclick="document.getElementById('blue1').className='event_visible'; return false;">click me</a>
<a name="blue1"></a>
<div class="event" id="blue1">
(stuff)
</div>
</body>
</html>
I've tried it with the standard xhtml strict and the old fashion html4 (like the code above) but the crazy thing still won't work in IE.
Returns a reference to the first object with the specified value of the ID or NAME attributeReturns a reference to the first object with the specified ID value.[msdn.microsoft.com...]
[msdn.microsoft.com...]