Forum Moderators: open
The lists bullet-points disappear whenever I click on the second UL link and generally there's some weird behaviour. Any ideas why? Could it be a conflict with some other JS code? Here's the code (and thanks in advance!):
Javascript
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
HTML
<div id="pagenav">
<ul>
<li><a href="#" onclick="toggle_visibility('b-d');">List 1</a>
<ul id='b-d'>
<li class="active"><a href="/url">page 1</a></li>
<li><a href="/url">page 2</a></li>...
</ul><!-- End show-hide b-d -->
</li>
<li><a href="#" onclick="toggle_visibility('r');">List 2</a>
<ul id='redbridge' style="display:none;">
<li><a href="/url">page 1</a></li>
<li><a href="/url">page 2</a></li>...
</ul><!-- End show-hide r -->
</li>
</ul>
</div> <!-- end div#pagenav -->
e.style.display = 'block';
I haven't tried it, but does this work instead of setting it to 'block'?
e.style.display = '';
<li><a href="#" onclick="toggle_visibility('r');">List 2</a>
<ul id='redbridge' style="display:none;">
should be
<li><a href="#" onclick="toggle_visibility('redbridge');">List 2</a>
<ul id='redbridge' style="display:none;">
Seems to work fine once that's fixed. Also something to help economize your code, it's called short-circuit evaluation:
function toggle_visibility(id) {
var e = document.getElementById(id);
e.style.display = (e.style.display == 'block')?'none':'block';
}
Note that I tested without benefit of style sheets you may have. If it's the list-dot that is disappearing for you, this can only mean it's something in your style sheets. The list dots are all visible here, IE7.