Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2005, 03:49 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default Div Question

Hi,

I have a page that has about 12 divs, each one containing menus. They are all classed in css so manipulation is quite easy. But what I am trying to do is to write a script that will cater for two screen resolutions and resize every div on the page depending on the screen res. Is there a way to reference every div at the same type? Its probably really simple but for the life of me I can't figure it out.

TIA
interrupt

__________________
\'sync\' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
 
Old July 19th, 2005, 04:54 AM
Authorized User
 
Join Date: Jul 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prophet Send a message via MSN to prophet
Default

"Is there a way to reference every div at the same type?"

... do you mean, every DIV of the same class?

 
Old July 19th, 2005, 04:56 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, mistype, I meant "at the same time".

 
Old July 19th, 2005, 04:58 AM
Authorized User
 
Join Date: Jul 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prophet Send a message via MSN to prophet
Default

You can walk through the document's nodes, check to see if its a DIV, and then do whatever you'd like to it.

 
Old July 19th, 2005, 05:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

document.body.getElementsByTagName("DIV");

is this what you want?
 
Old July 19th, 2005, 05:15 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah lol. Dunno why I couldn't work that out.

Thanks guys

 
Old July 19th, 2005, 05:19 AM
Authorized User
 
Join Date: Jul 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prophet Send a message via MSN to prophet
Default

Doh. Heh. Forgot about getElementsByTagName. :-P

 
Old July 19th, 2005, 05:21 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Im very tired. Thats my excuse and Im sticking to it. :D

 
Old July 19th, 2005, 08:46 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I like Dean Edwards' cssQuery() for stuff like that.
http://dean.edwards.name/my/cssQuery/

Basically it will get all elements using a CSS selector and returns an array of nodes that match the selector.

// query a class name
var tags = cssQuery('div.classname');

for (var i in tags)
{
   // Do stuff
   tags[i].style.background = 'blue';
}

You can also do stuff like this:
var tags = cssQuery('div > span.directchild');

var tags = cssQuery('div div.descendant');

It is also cross-platform, and works in IE, Firefox, Opera, and Safari.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML question on div jastao XSLT 6 June 6th, 2008 05:24 PM
div within a div and inherting the height brettdavis4 CSS Cascading Style Sheets 1 January 23rd, 2007 09:59 AM
Rookie question: container div not containing CFGerry BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 6 September 1st, 2005 09:00 PM
Question about "floating div" JavaScript ks@millershea.com Javascript 0 April 17th, 2005 12:19 PM
Div again... Nitin_sharma HTML Code Clinic 3 February 11th, 2005 04:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.