Re: (DOM)Compute the sum of width of elements contained in blockleve element
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: (DOM)Compute the sum of width of elements contained in blockleve element

From: Zif <zifud@hotmail.com>
Date: Wed Feb 08 2006 - 04:41:05 CET

Luke Matuszewski wrote:
> Hi.
> I know that it is hard problem (as hard as CSS and HTML layouting rules
> apply), but maybe someone
> has some code or idea how to start it. For now i know i will cssQuery:
>
> <URL:http://dean.edwards.name/my/cssQuery/>
>
> My point of interest is all elements inside <div class="bodycontent">
> [...] </div>, so to get direct descendant elements i will use:
>
> var tags = cssQuery("div[class='bodycontent'] > *");
>
> My question is about returned elements (which represent html tags) - do
> they have some property which will indicate the actual width which they
> take ?

Elements don't represent tags anymore than a building represents the
plans that were used to build it. Anyhow, enough semantic crap :-)

You are looking for clientHeight and clientWidth, but beware - they
might not be constent across all browsers and you need to use a strict
doctype. The MozDev reference below also has links to the MS documentation:

MozDev:
<URL:http://developer.mozilla.org/en/docs/DOM:element.clientHeight>

Notes on compatibility:
<URL:http://www.quirksmode.org/viewport/compatibility.html>

You can get various style properties that have cascaded using
currentStyle (IE) and getComputedStyle (most others) but again,
implementations vary and support may be patchy:

<URL:
http://groups.google.co.uk/group/comp.lang.javascript/browse_frm/thread/138e7cccd530e639/d58c702286daf5c6?q=currentStyle+computedstyle&rnum=1#d58c702286daf5c6
>

-- 
Zif
Received on Mon May 1 03:09:39 2006