473,797 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.na me/my/cssQuery/>

My point of interest is all elements inside <div class="bodycont ent">
[...] </div>, so to get direct descendant elements i will use:

var tags = cssQuery("div[class='bodycont ent'] > *");

My question is about returned elements (which represent html tags) - do
they have some property which will indicate the actual width which they
take ?

BR.
Luke Matuszewski

Feb 8 '06 #1
7 1574
Zif
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.na me/my/cssQuery/>

My point of interest is all elements inside <div class="bodycont ent">
[...] </div>, so to get direct descendant elements i will use:

var tags = cssQuery("div[class='bodycont ent'] > *");

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.mozil la.org/en/docs/DOM:element.cli entHeight>

Notes on compatibility:
<URL:http://www.quirksmode. org/viewport/compatibility.h tml>
You can get various style properties that have cascaded using
currentStyle (IE) and getComputedStyl e (most others) but again,
implementations vary and support may be patchy:

<URL:
http://groups.google.co.uk/group/com...8c702286daf5c6

--
Zif
Feb 8 '06 #2
Luke Matuszewski wrote:
My question is about returned elements (which represent html tags)
Elements do not represent HTML tags. HTML elements consist of tags (start
and end tag, where the latter or both may or may not be optional), and they
also may consist of content.

Accessing the DOM with an ECMAScript implementation returns references to
element objects which represent elements in the markup.
- do they have some property which will indicate the actual width which
they take ?


- getComputedStyl e(objRef, pseudoElem).wid th
(standards compliant: Gecko, Opera)
- objRef.offsetWi dth (proprietary: Gecko, IE, Opera)
- objRef.currentS tyle.width (proprietary: IE)
PointedEars
Feb 8 '06 #3
Zif wrote:
Luke Matuszewski wrote:
My question is about returned elements [...] 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, [...]


He is not:

,-[Gecko DOM Reference on .clientHeight]
| Returns the inner height of an element in pixels, including padding but
| not the horizontal scrollbar height, border, or margin.

,-[MSDN Library HTML and DHTML Reference on .clientHeight]
| Retrieves the height of the object including padding, but not including
| margin, border, or scroll bar.

,-[Gecko DOM Reference on .clientWidth]
| clientWidth is the inner width of an element in pixels. It includes
| padding but not the vertical scrollbar (if present, if rendered), border
| or margin.

,-[MSDN Library HTML and DHTML Reference on .clientWidth]
| Retrieves the width of the object including padding, but not including
| margin, border, or scroll bar.
PointedEars
Feb 8 '06 #4
Thomas 'PointedEars' Lahn wrote:
Luke Matuszewski wrote:
My question is about returned elements [...] - do they have some property
which will indicate the actual width which they take ?


- getComputedStyl e(objRef, pseudoElem).wid th
(standards compliant: Gecko, Opera)
[...]


That is not quite correct. getComputedStyl e() as introduced in W3C DOM
Level 2 Style returns (a reference to) a CSSStyleDeclara tion object which
does not have a `width' property nor does it have a namedItem() method to
allow for this property access in ECMAScript implementations . So the fully
standards compliant DOM access would be

getComputedStyl e(objRef, pseudoElem).get PropertyValue(" width")

which is supported only in the Gecko DOM (where the global Window object
appears to implement the ViewCSS interface). It should also be noted that
of all the DOMs tested, the KHTML DOM (Konqueror, Safari), Version 3.5.1
(Konqueror 3.5.1), does not appear to support any of the mentioned access
methods.
PointedEars
Feb 8 '06 #5
Thomas 'PointedEars' Lahn wrote:
That is not quite correct. *getComputedSty le() as introduced in W3C DOM
Level 2 Style returns (a reference to) a CSSStyleDeclara tion object which
does not have a `width' property nor does it have a namedItem() method to
allow for this property access in ECMAScript implementations . *So the
fully standards compliant DOM access would be

getComputedStyl e(objRef, pseudoElem).get PropertyValue(" width")

which is supported only in the Gecko DOM (where the global Window object
appears to implement the ViewCSS interface). It should also be noted that
of all the DOMs tested, the KHTML DOM (Konqueror, Safari), Version 3.5.1
(Konqueror 3.5.1), does not appear to support any of the mentioned access
methods.


My test case was flawed. Different to the `offsetWidth' property,
getComputedStyl e() values are not (reliably) available in the Opera
and KHTML DOM before the document was fully loaded. When I appended
a text node with the retrieved value to the `body' element when its
`load' event fired, that text node contained the expected value.
So the support matrix is currently

Gecko IE Opera KHTML SC[0]
------------------------------------------------------------------ -----
getComputedStyl e(objRef, [1], [2] - [4] [5] Yes
pseudoElem)
..getPropertyVa lue("width")

getComputedStyl e(objRef, [1], [2] - [4] [5] Yes?
pseudoElem).wid th

objRef.offsetWi dth [1], [2] 5.0+ [3] [4] [5] No

objRef.currentS tyle.width - 5.0+ [3] - - No
------------------------------------------------------------------ -----

where objRef === document.body and pseudoElem === null.

It is Netscape 4.x --

Mozilla/4.8 [en] (X11; U; Linux 2.6.15.1-20060130.184242 +0100 i686)

-- that supports neither access method mentioned.
PointedEars
___________
[0] Standards compliant; see quote for "Yes?"
[1] Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060205
Debian/1.7.12-1.1
[2] Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20060110
Debian/1.5.dfsg-4 Firefox/1.5 Mnenhy/0.7.3.0
[3] Cannot test here, version information from MSDN Library
[4] Opera/8.51 (X11; Linux i686; U; en)
[5] Mozilla/5.0 (compatible; Konqueror/3.5;
Linux 2.6.15.1-20060130.184242 +0100; X11; i686; de, en_US)
KHTML/3.5.1 (like Gecko) (Debian package 4:3.5.1-1)
Feb 8 '06 #6
Zif
Thomas 'PointedEars' Lahn wrote:
Zif wrote:

Luke Matuszewski wrote:
My question is about returned elements [...] 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, [...]

He is not:


Maybe, maybe not - or can you read minds?

Maybe you only read to here then punched out a knee-jerk response - or
are you deliberately ignoring the reference to the documentation and
getComputedStyl e/currentStyle methods?
--
Zif
Feb 8 '06 #7
Zif wrote:
Thomas 'PointedEars' Lahn wrote:
Zif wrote:
Luke Matuszewski wrote:
My question is about returned elements [...] 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, [...] He is not:


Maybe, maybe not - or can you read minds?


He is definitely not, and one does not need to be able to read minds for
that, a minimum clue suffices. He asked about the actual width of the
element. As I pointed out, the client* properties do not provide that
kind of information as they do not take scrollbars, borders and margins
of the element into account. The offset* properties do, with more
consistent results among user agents and rendering modes.
Maybe you only read to here then punched out a knee-jerk response - or
are you deliberately ignoring the reference to the documentation and
getComputedStyl e/currentStyle methods?


Maybe not.
PointedEars
Feb 9 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2289
by: Csaba2000 | last post by:
I've been thinking the replies to my earlier post. I can attach a method to a DOM element as below. But instead of assigning it to each element individually, I would rather have it as a method of every DOM element (and failing that, as a method of all javascript objects) - that would be much more tidy and memory conscious. What is the proper syntax for this, because I can't seem to get it to work on either IE 6 or Firefox 1.0.1 with...
4
5137
by: kj7ny | last post by:
I have been able to get xml.dom.minidom.parse('somefile.xml') and then dom.getElementsByTagName('LLobjectID') to work to the point where I get something like: which I can get down to <DOM Element: LLobjectID at 0x13cba08but then I can't find any way to just get the value out from the thing! ..toxml() returns something like: u'<LLobjectID><!]></ LLobjectID>'. How do I just get the 1871203 out of the DOM Element?
9
4035
by: mevryck | last post by:
Greetings I have a huge Javascript with inclusion of external scripts and all. I got this by doing a XSLT . Now I have the contents in a Javascript variable, but I'm not able to update the element with the javascript contents. But when viewed as a seperate HTML file with the below contents I'm able to see the milonic menu http://www.milonic.com . <div>
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10468
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.