Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-20-2008, 09:26 AM   PM User | #1
rhinodog8
New Coder

 
Join Date: Aug 2008
Location: Colfax, California USA
Posts: 64
Thanks: 3
Thanked 5 Times in 5 Posts
rhinodog8 is an unknown quantity at this point
Prototype: get all childElements with <img> & combine their height for 1 value

I don't really know where to start even in theory, but I know there is a way. Could someone point me into the right direction?
rhinodog8 is offline   Reply With Quote
Old 11-21-2008, 03:55 PM   PM User | #2
ohgod
Regular Coder

 
ohgod's Avatar
 
Join Date: Jun 2008
Location: Ohio
Posts: 579
Thanks: 6
Thanked 69 Times in 69 Posts
ohgod is on a distinguished road
$$('img') would pull all img tags

http://www.prototypejs.org/api/utility/dollar-dollar

suffix it with an each statement to walk through and get all the values:

http://www.prototypejs.org/api/array/each

and use getHeight to get the height and add them up...

http://www.prototypejs.org/api/element/getheight

Code:
function(){

var total = 0;

$$('img').each(function(s){ elval = s.getHeight();   
total = total + elval;
}) return total; }
play around with it, i'm sure i made a couple dumb mistakes and it's untested. anyone else feel free to double check that for retardation.
ohgod is offline   Reply With Quote
Users who have thanked ohgod for this post:
rhinodog8 (11-29-2008)
Old 11-29-2008, 01:32 AM   PM User | #3
rhinodog8
New Coder

 
Join Date: Aug 2008
Location: Colfax, California USA
Posts: 64
Thanks: 3
Thanked 5 Times in 5 Posts
rhinodog8 is an unknown quantity at this point
Wow, thanks so much. Your code worked right out of the box. But i modified it a little for an each function inside a specific div containing imgs and to include the offset width of the imgs.

also eval threw an error, although it got the heights, so I just used s as the variable.

Heres what my code if anyone was wandering...
Code:
total=0;
//search picture li for first div's images and combines all the widths of each image

b.childElements()[0].select('img').each(function (w) {s=w.offsetWidth;total= total+s;});

//Set the inner pcture div to all the images combined width & plus 3 for IE6

b.childElements()[0].setStyle({width: total+3+'px'});

Last edited by rhinodog8; 11-29-2008 at 01:35 AM..
rhinodog8 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:21 AM.


Advertisement
Log in to turn off these ads.