[Javascript] [Beginner] What is going on with my show/hide function?

Aaron Bassett aaronbassett at gmail.com
Mon Nov 13 15:00:12 CST 2006


If you already have an answer your happy with ignore this but otherwise it
might help.

function toggleDisplay(id) {
    var el = document.getElementById(id);
    if(el.className == 'hidden') {
        el.className = '';
    } else {
        el.className = 'hidden';
    }
}

<div id='toHide'>My div content</div>
<a href='#' onclick="toggleDisplay('toHide'); return false;">Toggle
display</a>

You might want to perform a better check than just looking for an exact
match on the className, like prototype's Element.hasClassName but this is
just a quick sample to get you started.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20061113/706101e8/attachment.htm>


More information about the Javascript mailing list