Anyway to find the height of a #div

D

Developer

Anyone know how to figure out how tall a #div is after its rendered by a browser. This way I can display additional ads if there is room.
 
D

Developer

What I am trying to do is see if there is room for more ads on the TOC left
column. For example if its say 900px then I can display a single 120x640
tower ad, but if it's a bit smaller than I need to show a 120x320 tower ad.

My toc #div is just wide enough for tower ads and I wanted to be able to
show more if there is room based on the resulting document sizes.

Then a quick script can cure my problem.
 
T

Thomas 'PointedEars' Lahn

Developer said:
Looks like scrollHeight is what I need, this way I can show ads ad nauseum.

When using Latin phrases, one should know a bit about them: ad nauseam ("to
the point of nausea", "the sensation of unease and discomfort in the stomach
with an urge to vomit." [Wikipedia]).

Thank you for telling us your domain, so that we can configure our DNS
servers accordingly.


PointedEars
 
T

Thomas Allen

When using Latin phrases, one should know a bit about them: ad nauseam ("to
the point of nausea", "the sensation of unease and discomfort in the stomach
with an urge to vomit." [Wikipedia]).

Judging by his homepage's background color, he may indeed mean it
literally.

Thomas
 
J

JR

Anyone know how to figure out how tall a #div is after its rendered by a browser. This way I can display additional ads if there is room.

I've been testing (not fully tested yet) this JS code by John Resig's
book. fullHeigth() will return an element's height even if that
element is not displayed (display: 'none'):

function fullHeight( elem ) {
// If the element is being displayed, then offsetHeight
// should do the trick, barring that, getHeight() will work.
if ( getStyle( elem, 'display' ) != 'none' )
return elem.offsetHeight || getHeight( elem );

// Otherwise, we have to deal with an element with a display
// of none, so we need to reset its CSS properties to get a more
// accurate reading.
var old = resetCSS( elem, {
display: '',
visibility: 'hidden',
position: 'absolute'
});

// Figure out what the full height of the element is, using
clientHeight
// and if that doesn't work, use getHeight
var h = elem.clientHeight || getHeight( elem );

// Finally, restore the CSS properties back to what they were.
restoreCSS( elem, old );

// and return the full height of the element.
return h;
}

function getHeight( elem ) {
// Gets the computed CSS value and parses out a usable number.
return parseInt( getStyle( elem, 'height' ) );
}

function resetCSS( elem, prop ) {
var old = {};

// Go through each of the properties
for ( var i in prop ) {
// Remember the old property value
old[ i ] = elem.style[ i ];

// And set the new value
elem.style[ i ] = prop;
}

// Retun the set of changed values, to be used by restoreCSS
return old;
}

// A function for restoring the side effects of the resetCSS function
function restoreCSS( elem, prop ) {
// Reset all the properties back to their original values
for ( var i in prop )
elem.style[ i ] = prop[ i ];
}

function getStyle( elem, name ) {
// If the property exists in style[], then it's been set recently
(and is current)
if (elem.style[name])
return elem.style[name];

// Otherwise, try to use IE's method
else if (elem.currentStyle)
return elem.currentStyle[name];

// Or the W3C's method, if it exists
else if (document.defaultView &&
document.defaultView.getComputedStyle) {
// It uses the traditional 'text-align' style of rule writing,
instead of textAlign
name = name.replace(/([A-Z])/g,"-$1");
name = name.toLowerCase();

// Get the style object and get the value of the property (if
it exists)
var s = document.defaultView.getComputedStyle(elem,"");
return s && s.getPropertyValue(name);

// Otherwise, we're using some other browser
} else
return null;
}

Hopefully someone will come up with something better than that.

Cheers,
Joao Rodrigues
 
D

David Mark

I've been testing (not fully tested yet) this JS code by John Resig's
book.

What a complete waste of time. Just assume it doesn't work.
fullHeigth() will return an element's height even if that
element is not displayed (display: 'none'):

Which is a completely senseless end-around for poorly designed
applications (or libraries that want to do everything for you.)
function fullHeight( elem ) {
    // If the element is being displayed, then offsetHeight
    // should do the trick, barring that, getHeight() will work.
    if ( getStyle( elem, 'display' ) != 'none' )
        return elem.offsetHeight || getHeight( elem );

What sort of nonsense is that? Regardless of what getHeight does, an
offsetHeight can be 0. Missing brackets, early returns; this looks
like Resig's work.
    // Otherwise, we have to deal with an element with a display

No you don't.
    // of none, so we need to reset its CSS properties to get a more
    // accurate reading.
    var old = resetCSS( elem, {
        display: '',

LOL. If you set out to solve *every* problem, you must at least be
aware of the possibilities.
        visibility: 'hidden',
        position: 'absolute'
OMFG.

    });

    // Figure out what the full height of the element is, using
clientHeight
    // and if that doesn't work, use getHeight
    var h = elem.clientHeight || getHeight( elem );

Why the sudden detour? What do you consider the "full height" to
mean?
    // Finally, restore the CSS properties back to what they were.
    restoreCSS( elem, old );

    // and return the full height of the element.

Meaningless result.
    return h;

}

function getHeight( elem ) {
    // Gets the computed CSS value and parses out a usable number.
    return parseInt( getStyle( elem, 'height' ) );

So, not even close. Also missing a radix (and you wanted parseFloat
anyway.)
}

function resetCSS( elem, prop ) {
    var old = {};

    // Go through each of the properties
    for ( var i in prop ) {

Definitely a Resig design, blundering straight into an age-old (and
clearly avoidable) issue.
        // Remember the old property value
        old[ i ] = elem.style[ i ];

        // And set the new value
        elem.style[ i ] = prop;
    }

    // Retun the set of changed values, to be used by restoreCSS
    return old;

}

// A function for restoring the side effects of the resetCSS function
function restoreCSS( elem, prop ) {
    // Reset all the properties back to their original values
    for ( var i in prop )
Again.

        elem.style[ i ] = prop[ i ];

}

function getStyle( elem, name ) {
    // If the property exists in style[], then it's been set recently
(and is current)


Are those your comments or his? In any event, they make very little
sense.
    if (elem.style[name])
        return elem.style[name];

    // Otherwise, try to use IE's method
    else if (elem.currentStyle)

Oops, Resig still can't figure out IE. Also, this is not a method and
the *property* is not specific to IE (e.g. Opera has this, so checking
it before the standard method is nuts.)
        return elem.currentStyle[name];

Oops again. IE doesn't *compute* styles, so this could be anything
from "5em" to "1%" to "auto."

Remember this?

function getHeight( elem ) {
// Gets the computed CSS value and parses out a usable number.
return parseInt( getStyle( elem, 'height' ) );

That's no good at all, is it? 5em will be interpreted as 5 pixels.
Values that can't be parsed as numbers (e.g. "auto") will return NaN.
    // Or the W3C's method, if it exists
    else if (document.defaultView &&
document.defaultView.getComputedStyle) {

Don't detect host methods by type conversion. Search the archive (or
Google) for isHostMethod.
        // It uses the traditional 'text-align' style of rule writing,
instead of textAlign
        name = name.replace(/([A-Z])/g,"-$1");
        name = name.toLowerCase();

What does?
        // Get the style object and get the value of the property(if
it exists)
        var s = document.defaultView.getComputedStyle(elem,"");
        return s && s.getPropertyValue(name);

That's what I thought. You are advised to stay away from
getPropertyValue for compatibility reasons (not to mention you can
skip the name translation.)
    // Otherwise, we're using some other browser
    } else
        return null;

Interesting choice. So this function can be expected to return almost
anything.
}

Hopefully someone will come up with something better than that.

First you will have to clearly define the problem. I don't see the
question from this attempt at an answer.
 
J

JR

Which is a completely senseless end-around for poorly designed
applications (or libraries that want to do everything for you.)

Looks as though you haven't told me anything.
What sort of nonsense is that?  Regardless of what getHeight does, an
offsetHeight can be 0.  Missing brackets, early returns; this looks
like Resig's work.

Does the lack of brackets invalidate the code? You're picking apart a
couple minor issues.
Why the sudden detour?  What do you consider the "full height" to
mean?

This was the only usable part of your long and boring analysis.

So, not even close.  Also missing a radix (and you wanted parseFloat
anyway.)

Do you really expect heights such as "08px" or "09px". In this
specific case radix is useless and Resig is aware of that. But you are
the Very keen knowledgeable guy.

<bla-bla-bla snipped>

Ok, that was a nice try to debunk the work of John Resig, but your
prototype of response didn't aggregate anything to the OP's problem.
You even sounded like a peeved child crying out loud: "Look Mom, John
Resig has stolen my Teddy Bear!" Indeed your anti-jQuery crusade
really sucks!

I could only understand your "answer" as the cry of a VERY resentful
person. Like it or not, you should RESIGn yourself to the inevitable
facts that RESIG has written a good selling book, he's known worldwide
(YouTube, international conferences), and he was hired by Mozilla
Foundation probably earning a LOT of money. And what about you, David
Mark?
 
J

John G Harris

On Sun, 28 Jun 2009 at 04:25:24, in comp.lang.javascript, JR wrote:

Like it or not, you should RESIGn yourself to the inevitable
facts that RESIG has written a good selling book, he's known worldwide
(YouTube, international conferences), and he was hired by Mozilla
Foundation probably earning a LOT of money. And what about you, David
Mark?

Allen Stanford was also known world-wide and was paid even more money.

John
 
D

David Mark

Looks as though you haven't told me anything.

I'd look again. Perhaps you didn't understand.
Does the lack of brackets invalidate the code? You're picking apart a
couple minor issues.

Uh no, *you* have picked the most minor of the issues mentioned.
This was the only usable part of your long and boring analysis.

Not at all. Read it again.
Do you really expect heights such as "08px" or "09px". In this
specific case radix is useless and Resig is aware of that. But you are
the Very keen knowledgeable guy.

You are clueless. Resig takes whatever is in the style (or
currentStyle) property and runs with it (no checks at all.)
<bla-bla-bla snipped>

Oh, of course. Snip all the rest of the points.
Ok, that was a nice try to debunk the work of John Resig, but your
prototype of response didn't aggregate anything to the OP's problem.

Nobody knows exactly what the OP's problem is. You on the other
hand...
You even sounded like a peeved child crying out loud: "Look Mom, John
Resig has stolen my Teddy Bear!" Indeed your anti-jQuery crusade
really sucks!

I take time out to correct *your* posted code and this is your
response. *You* really suck.
I could only understand your "answer" as the cry of a VERY resentful
person.

Then you have the mentality of a small child.
Like it or not, you should RESIGn yourself to the inevitable
facts that RESIG has written a good selling book, he's known worldwide

I don't give a **** if he put this shit in a book. You posted it
*here* as *advice* for a neophyte. Get it?
(YouTube, international conferences), and he was hired by Mozilla

Christ on a crutch. Any twit can post videos on YouTube. And I
neither know nor care about whatever he does for Mozilla.
Foundation probably earning a LOT of money. And what about you, David
Mark?

Your research into these matters appears lacking (and it's none of
your business anyway.)
 
D

David Mark

On Sun, 28 Jun 2009 at 04:25:24, in comp.lang.javascript, JR wrote:



Allen Stanford was also known world-wide and was paid even more money.

As was Bernie Madoff and countless other frauds. And what do you
imagine JR stands for? ;)
 
G

Gregor Kofler

JR meinte:
I could only understand your "answer" as the cry of a VERY resentful
person. Like it or not, you should RESIGn yourself to the inevitable
facts that RESIG has written a good selling book, he's known worldwide
(YouTube, international conferences), and he was hired by Mozilla
Foundation probably earning a LOT of money.

Ah a true disciple. John will be proud of you. I'm pretty sure
worshipping Him will make you a good JS coder. One day. Eventually. Or so.

Gregor
 
D

David Mark

JR meinte:


Ah a true disciple. John will be proud of you. I'm pretty sure
worshipping Him will make you a good JS coder. One day. Eventually. Or so..

LOL. Look carefully at the initials. Odd battle to choose though.
 
J

JR

JR meinte:


Ah a true disciple. John will be proud of you. I'm pretty sure
worshipping Him will make you a good JS coder. One day. Eventually. Or so..

Um, no, but I see that Mark's cap fits in you too...
I don't give a damn to John Resig and his jQuery. What is annoying is
to be forced to watch all this clownery about jQuery almost everyday,
as though cljs was a circus with 'Dave the Clown' in the centre of the
ring.

As Mark (Dave) and Resig live in the same country, they could spare
our time by duelling and killing each other, thus making a favour to
the rest of the world. But no, Mark doesn't seem to have the courage
to challenge Resig in public. Look at Mark's horrible web 1.0 website
(cinsoft.net), and try to find any of the hallucinated posts
condemning both jQuery and their followers. And the man still calls
himself in his 'resume' (www.linkedin.com/in/davidmark) as
"Experienced software designer and programmer, Web developer, IT
manager and consultant. Ten years as a top-level IT executive with
last eight as head of own firm." - What a ridiculous person!

Know what? Mark is just a coward, who knows that the future of his
*business* would be seriously compromised by attacking John Resig and
his zillion supporters using a true website. That's why he lurks in
jQuery group and only barks furiously in a Usenet group (cljs).

I can imagine *all* the Cinsoft staff (maybe a secretary, a security
guard and some trainees?) congratulating their boss in the office by
his brilliant anti-jQuery crusade: "Mr Mark, don't mind if 99.9% of
the world don’t agree with you about jQuery, because, for us, you're
the best developer in the world”. That’s because everyone know the Law
1 – Never Outshines the Master. However, Mark should learn the Law 2 -
Never put too Much Trust in Friends…

Sorry people, but Google, Dell, Bank of America, NBC, CBS,
Technoratti, Mozilla Foundation, Wordpress, Drupal amongst other must
support jQuery for a good reason. Please let me know if any of the big
companies support "My Library" or "vxJS".

Gregor
--http://www.gregorkofler.comhttp://web.gregorkofler.com- vxJS, a JS lib in progress
</SPAM>

Like you, I'm just a coder in progress.
 
D

David Mark

Um, no, but I see that Mark's cap fits in you too...
I don't give a damn to John Resig and his jQuery. What is annoying is

Then do shut up about them.
to be forced to watch all this clownery about jQuery almost everyday,

People keep bringing them up. Take you and this for examples.
as though cljs was a circus with 'Dave the Clown' in the centre of the
ring.

As Mark (Dave) and Resig live in the same country, they could spare

I would prefer that you not refer to me as Dave.
our time by duelling and killing each other, thus making a favour to
the rest of the world. But no, Mark doesn't seem to have the courage
to challenge Resig in public. Look at Mark's horrible web 1.0 website
(cinsoft.net)

Nothing there. There is something here (for the moment):

http://www.cinsoft.net/mylib.html

Is that your Web1.0 example? As far as cross-browser scripting goes,
that may well be one of the most significant and over-the-top Web 2.0
application ever published to the Web, even if only the learning
opportunities are considered.
, and try to find any of the hallucinated posts

What hallucinated posts? Never mind, withdrawn.
condemning both jQuery and their followers. And the man still calls

More like pointing out grievous errors in their code. That matters
more than their videos or the commercial appeal of their ridiculous
Website(s).
himself in his 'resume' (www.linkedin.com/in/davidmark) as
"Experienced software designer and programmer, Web developer, IT
manager and consultant. Ten years as a top-level IT executive with
last eight as head of own firm." - What a ridiculous person!

It's not that ridiculous.
Know what? Mark is just a coward, who knows that the future of his
*business* would be seriously compromised by attacking John Resig and
his zillion supporters using a true website. That's why he lurks in
jQuery group and only barks furiously in a Usenet group (cljs).

Using a true Website? You seem confused on a number of points. I
don't lurk in the jQuery group and criticizing code is not attacking
anybody. Resig did have the nerve to come in here and attack me a
couple of years back. Ironically, it was in response to predictions
about his code that all ended up coming true.
I can imagine *all* the Cinsoft staff (maybe a secretary, a security
guard and some trainees?) congratulating their boss in the office by
his brilliant anti-jQuery crusade: "Mr Mark, don't mind if 99.9% of
the world don’t agree with you about jQuery, because, for us, you're

Who conducted that study?
the best developer in the world”. That’s because everyone know the Law
1 – Never Outshines the Master. However, Mark should learn the Law 2 -
Never put too Much Trust in Friends…

What?

Sorry people, but Google, Dell, Bank of America, NBC, CBS,
Technoratti, Mozilla Foundation, Wordpress, Drupal amongst other must
support jQuery for a good reason.

Oh for God's sake. They all have incompetent Web designers. Nobody
else in those organizations knows what a "jQuery" or a "JS Ninja" is.
Please let me know if any of the big
companies support "My Library" or "vxJS".

Depends on what you mean by big (and I don't know any vxJS.)

Oh. Where is the connection here? Because Gregor doesn't seem to
care for jQuery either? He's a .1 percenter? You sound like a
paranoid cult member (which you undoubtedly are.)
Like you, I'm just a coder in progress.

You aren't like me.
 
G

Gregor Kofler

JR meinte:
Sorry people, but Google, Dell, Bank of America, NBC, CBS,
Technoratti, Mozilla Foundation, Wordpress, Drupal amongst other must
support jQuery for a good reason.

I can imagine some of the reasons. I'm pretty sure they don't match with
the ones *you* imagine, but I am right.
Please let me know if any of the big
companies support "My Library" or "vxJS".

Guess what - some companies use jQuery *and* vxJS beside each other.
Like you, I'm just a coder in progress.

I'm inclined to state that you are an idiot, nothing else. Otherwise
you'd know what a signature is. In addition: if you don't see the
shortcomings of the critized script, to road ahead is long and winding.
Better stick to your script kiddie peers, and leave the adults alone.

Gregor
 
A

ace

Gregor said:
the ones *you* imagine, but I am right.


Guess what - some companies use jQuery *and* vxJS beside each other.

It seems unusual, do you know why they use two libs at once?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top