I got asked about something similar on a forum not long ago I&#39;ll c&amp;p my response here incase its of use to you:<br><br>Ok this isn&#39;t the quickest way to go about it but it allows you to use
classes to toggle visibility rather than applying the style directly.<br>
<br>
The most part of it is a butchered piece of prototype.js so if you are
using a library/framework with its own class handling methods you can
simply use them instead.<br>
<br>
Oh and this is in no way actually guaranteed to work - I&#39;ve just
written this out quickly and it is completely 100% untested. Its only
meant as an idea incase you want to do something similar.<br>
<br>
<div style="margin: 5px 20px 20px;">
        <div class="smallfont" style="margin-bottom: 2px;">Code:</div>
        <pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 498px; text-align: left;">/*<br>*  Example usage: <br>*      notice.toggle(id);<br>*      notice.show
(id);<br>*      notice.hide(id);<br>*/<br><br>notice={<br><br>        hideClass&quot;hide&quot;,<br>        <br>        toggle:function(id) {<br>                if(this.hasClassName(id this.hideClass)) {<br>                        this.removeClassName(id this.hideClass);<br>                } else {
<br>                        this.addClassName(id this.hideClass);<br>                }<br>        },<br>        <br>        show:function(id) {<br>                this.addClassName(id this.hideClass);<br>        },<br>        <br>        hide:function(id) {<br>                this.removeClassName(id this.hideClass);<br>        },<br>
<br>        // Modified from prototype.js [ <a href="http://prototype.conio.net/">http://prototype.conio.net/</a> ]<br>        hasClassName:function(id, cName) {<br>                if(!document.getElementById(id)) return;<br>                var elClass = document.getElementById
(id).className;<br>                if (elClass.length == 0) return false;<br>                if (elClass == cName || elClass.match(new RegExp(&quot;(^|\\s)&quot; + cName + &quot;(\\s|$)&quot;))) return true;<br>                return false;<br>        },<br><br>        addClassName: function(id, cName) {
<br>                if(!document.getElementById(id)) return;<br>                var el = document.getElementById(id);<br>                if(!this.hasClassName(id, cName)) el.className = el.className + &quot; &quot; + cName;<br>        },<br>        <br>        removeClassName:function(id, cName) {
<br>                if(!document.getElementById(id)) return;<br>                if(!this.hasClassName(id, cName)) return;<br>                var el = document.getElementById(id);<br>                var elClass = el.className;<br>                if (elClass.length == 0) return;<br>                var newClass = &quot;&quot;;
<br>                var classes = elClass.split(&#39; &#39;);<br>                for(var i = classes.length-1; i &gt;= 0; --i){<br>                        if(classes[i] != cName) newClass += classes[i] + &quot; &quot;;<br>                }<br>                var sp = /^\s*(.*?)\s*$/;<br>                el.className
 = newClass.replace(sp, &quot;&quot;);<br>        }<br>}</pre>
</div><br><br><div><span class="gmail_quote">On 1/12/07, <b class="gmail_sendername">Alex Turner</b> &lt;<a href="mailto:Alex.Turner@project-network.com">Alex.Turner@project-network.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Dood,<br><br>I would place call onclick like this:<br><br>&lt;span class=&quot;click&quot; onclick=&#39;toggleMe(this)&#39;&gt;Hide this content&lt;/span&gt;<br><br>Then the toggle event handler gets a reference to the node from which it was called and hence has no chance of ambiguity :-)
<br><br>The other way that is also easy - but messier - is the way I did the selectable rows in a table - see <a href="http://nerds-central.blogspot.com">nerds-central.blogspot.com</a><br><br>Cheers<br><br>AJ<br><br>Dr Alexander J Turner
<br>Project Network<br>+44 (0) 7917 065072<br>Con Call: 0870 241 3425/3342654#<br><br>________________________________<br><br>From: <a href="mailto:javascript-bounces@LaTech.edu">javascript-bounces@LaTech.edu</a> on behalf of Bill Moseley
<br>Sent: Thu 1/11/2007 23:57<br>To: <a href="mailto:javascript@LaTech.edu">javascript@LaTech.edu</a><br>Subject: [Javascript] Help with closures<br><br><br><br>Or I think this is a closure issue.<br><br>I have a really simple and common task (that I&#39;m likely making hard), where I
<br>want to create a hide/show block.<br><br>So, the block of HTML looks basically like this:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;hidable&quot;&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;content&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span class=&quot;click&quot;&gt;Hide this content&lt;/span&gt;&lt;br /&gt;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content here<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;hidden&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;span class=&quot;click&quot;&gt;Show the content&lt;/span&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
<br><br>So clicking on &quot;Show&quot; or &quot;Hide&quot;, well shows or hides that block with<br>content.<br><br>The problem is when I have two of those blocks clicking on the &quot;hide&quot;<br>seems to get the right event but is hiding the wrong block.
<br><br>Here&#39;s a working demo:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://hank.org/hide.html">http://hank.org/hide.html</a><br><br><br><br>So, a page can have any number of the above blocks.&nbsp;&nbsp;The javascript<br>finds the blocks by looking for all &quot;hidable&quot; classes using Prototype&#39;s
<br>getElementsByClassName();<br><br>The onclick events are assigned to the spans with &quot;click&quot;.&nbsp;&nbsp;When the<br>even first I look at the parentNode&#39;s class name to know if should<br>hide or to show.<br><br>Basically in pseudo code I set up the events like so:
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;for div in get_by_class( &#39;hidable&#39; ) {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// get &lt;div&gt; elements for the two inner sections<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var content_div = get_class( &#39;content&#39;, div );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var hidden_div&nbsp;&nbsp;= get_class( &#39;hidden&#39;, div );
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// get the span for setting the events<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var show_span&nbsp;&nbsp; = get_class( &#39;click&#39;, content_div );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var hide_span&nbsp;&nbsp; = get_class( &#39;click&#39;, hidden_div );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// closure to call the toggle passing in the two &lt;div&gt;s
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var click_event = function(e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toggle( e, content_div, hidden_div );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Event.observe( show_span, &#39;click&#39;, show_event, false );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Event.observe( hide_span, &#39;click&#39;, show_event, false );
<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br><br>Then the event does:<br><br>function toggle ( event, content_div, hidden_div ) {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;look at event element&#39;s parent&#39;s class name to determine if should<br>&nbsp;&nbsp;&nbsp;&nbsp;hide or show.<br><br>}<br>
<br><br><br>--<br>Bill Moseley<br><a href="mailto:moseley@hank.org">moseley@hank.org</a><br><br>_______________________________________________<br>Javascript mailing list<br><a href="mailto:Javascript@LaTech.edu">Javascript@LaTech.edu
</a><br><a href="https://lists.LaTech.edu/mailman/listinfo/javascript">https://lists.LaTech.edu/mailman/listinfo/javascript</a><br><br><br><br>_______________________________________________<br>Javascript mailing list<br>
<a href="mailto:Javascript@LaTech.edu">Javascript@LaTech.edu</a><br><a href="https://lists.LaTech.edu/mailman/listinfo/javascript">https://lists.LaTech.edu/mailman/listinfo/javascript</a><br><br><br></blockquote></div><br>