|
-
May 28th, 2002, 09:57 AM
#1
Thread Starter
Frenzied Member
(javascript) getting a div's height
I have a div that will have a dynamic height. It will only vary on page load but will be different from time to time so I cannot hard code the height (need to know the height in a different function). Here is what I tried:
VB Code:
var temptest = getElementById('content').style.height;
alert(temptest);
this gives me the 'object expected' error...
any hints?
Michael
I'm off to GalahTech, hope to see you there.
If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.
-
May 28th, 2002, 10:08 AM
#2
Fanatic Member
style.width only sets it, not gets the value.
Heres the good old findxxxx functions.
example for <div id="layer1" style="position:absolute; left:100px;">
Code:
alert(findleft('layer1'));
this will (should) return 100.
Code:
function findleft(objectID){
if (findDom(objectID).left){return findDom(objectID).left;}
if (findDom(objectID).pixelLeft){return findDom(objectID).pixelLeft;}
if (findDom(objectID).offsetLeft){return findDom(objectID).offsetLeft;}
return 'null';
}
function findtop(objectID){
if (findDom(objectID).top){return findDom(objectID).top;}
if (findDom(objectID).pixelTop){return findDom(objectID).pixelTop;}
if (findDom(objectID).offsetTop){return findDom(objectID).offsetTop;}
return 'null';
}
function findwidth(objectID){
if (findDom(objectID).offsetWidth){return findDom(objectID).offsetWidth;}
if (findDom(objectID).clip.width){return findDom(objectID).clip.width;}
return 'null';
}
function findheight(objectID){
if (findDom(objectID).offsetHeight){return findDom(objectID).offsetHeight;}
if (findDom(objectID).clip.height){return findDom(objectID).clip.height;}
return 'null';
}
function findDom(objectID){
if (document.all){
return document.all(objectID);
} else if (document.getElementById){
return document.getElementById(objectID);
} else if (document.layers){
return (document.layers[objectID]);
}
}
-
May 28th, 2002, 10:44 AM
#3
Frenzied Member
Thanks Lee, that's one snippet for the templates directory!
-
May 28th, 2002, 02:29 PM
#4
Frenzied Member
Now if someone wanted to rewrite that in concise, compliant JavaScript. I think all of that would drop to twelve lines.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
May 28th, 2002, 04:06 PM
#5
Fanatic Member
Be my guest, Travis.
I only have it like that so I can snip the code as I need it. I use a lot of javascripts that way
-
May 28th, 2002, 05:10 PM
#6
Frenzied Member
-
May 29th, 2002, 08:36 AM
#7
Frenzied Member
Nothing is wrong with it. But it is 27 lines instead of 12.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
May 29th, 2002, 08:56 AM
#8
Frenzied Member
So how can you compact it more?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|