homepage Welcome to WebmasterWorld Guest from 54.166.53.169
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Loop to collect divs
ebby

5+ Year Member



 
Msg#: 3748099 posted 5:45 pm on Sep 19, 2008 (gmt 0)

Trying to turn div visiblitly to false with a loop. When the user hovers over a menu item I call the function getMenuName(this). Passing "this" into the function because I have named my divs after the menu items preceded by "myDiv"

Here is what I have so far:

function getMenuName(obj)
{
var objName;
objName = "mydiv" + obj.childNodes[0].nodeValue;
objShow = document.getElementById(objName)
objShow.style.visibility = "visible"
}

This works great to make the desired div visible, but now I need to turn off the others. How do I loop through the page and...

1 - Collect all divs that begin with "myDiv"

2 - Change visibilty to hidden.

Thanks in advance.

 

daveVk

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3748099 posted 2:41 am on Sep 20, 2008 (gmt 0)

You will need to collect all divs within page( or section in question).

var els = document.getElementsByTagName('div');

and check id of each.

Filipe

10+ Year Member



 
Msg#: 3748099 posted 2:35 am on Sep 21, 2008 (gmt 0)

I also strongly recommend looking into YUI (Yahoo's DHTML/AJAX framework), as they have a series of methods that work very well for these exact processes, for example:


var collection = YAHOO.util.Dom.getElementsByClassName('blah');

and "collection" will contain a collection of any object of class 'blah'.

f00sion

10+ Year Member



 
Msg#: 3748099 posted 8:15 pm on Sep 23, 2008 (gmt 0)

jquery:
$('.myclass').show();

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved