Michael-

Thanks for the tip. I was definitely confused that I didn't have an
element and it showed in my code.  I understood that my id selector
would only return one element, but I wasn't putting together that it
was a one element array.  I got that now.

I will fix my variable names right away.

--MERC.

On Oct 9, 12:01 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> I would change the name of the headerElem variable too. That name clearly
> indicates that it's supposed to be a DOM element, but it isn't. This will
> lead to much confusion.
>
> $() does not return a DOM element, it returns a jQuery object, which is an
> array of DOM elements (even in the case where there is only one).
>
> Merc, one convention you'll find in a lot of jQuery code is to use $ at the
> beginning of a variable that contains a jQuery object:
>
> var $header = $('#header');
> var headerHeight = $header.height();
>
> This gives you a visual reminder that the variable is a jQuery object, since
> it looks like the $ that was used to create the object in the first place.
>
> If you do want to get to the actual DOM element(s) inside a jQuery object,
> use array indexing. In the case of a #id selector, there is only a single
> element and you can use [0]:
>
> var $header = $('#header');
> var headerElement = $header[0];
> var headerHeight = headerElement.offsetHeight;
>
> -Mike
>
>   _____
>
> From: Karl Swedberg
>
> Hi Merc,
>
> If you want an integer, try this:
>
> var headerElem = $("#header");
> var headerHeight = headerElem.height();
>
> If you want the value with "px", try this:
>
> var headerElem = $("#header");
> var headerHeight = headerElem.css('height');
>
> Hope that helps.
>
> --Karl
> _________________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On Oct 9, 2007, at 1:02 AM, Merc70 wrote:
>
> I'm new to Javascript and jQuery, so I'm sorry if this is basic
> stuff. How do I access offsetHeight for an element? This is what I
> have, but offsetHeight comes up undefined:
>
> var headerElem = $("#header");
> var headerHeight = headerElem.offsetHeight;
>
> whereas this works:
> var docHeader = document.getElementById("header");
> headerHeight = docHeader.offsetHeight;
>
> Thanks --MERC

Reply via email to