[thelist] Need some JS help - unobtrusive popup - based on CLASS not id.

ben morrison morrison.ben at gmail.com
Fri Jun 15 11:17:46 CDT 2007


On 6/15/07, Jon Hughes <hughesj at firemtn.com> wrote:
> Here's what I have so far:
>
> function detpopup() {
> if (!document.getElementsByTagName || !document.getElementById) return
> false;
> if (!document.getElementById('content').className == 'detpopupcont')
> return false;
> var detpopup = document.getElementById('content').className =
> 'detpopupcont';
> detpopup.style.visibility='visible';
> }
>
>
> The HTML is like so:
>
> <div id="content">
> <div class="detpopupcont" style="visibility:hidden">This is hidden with
> no javascript</div>
> <div class="detpopupcont" style="visibility:hidden">This is hidden with
> no javascript</div>
> <div class="detpopupcont" style="visibility:hidden">This is hidden with
> no javascript</div>
> </div>
>
> When the page loads, I want all of those to become "visibility:visible"
> but this is my first bit of JS, and I need help :-/

I'm not quite sure what you are trying to achieve as usually you would
hide/show the elements with javascript for accessibility reasons, but
anyway...

There are a lot of functions that have been written for the lack of
getElementsByClass, here's one:

http://www.dustindiaz.com/getelementsbyclass/

this will return an array, so now you can loop through that array

var popUps= getElementsByClass('detpopupcont');

for(i=0;i<popUps.length;i++) {


-- 
Ben Morrison
http://www.benjaminmorrison.com



More information about the thelist mailing list