views:

92

answers:

4

How would you find out the width of a element that is wrapped by 20 odd other elements, but the only fixed width I know is the main wrapper's which is 800px. All child elements are generally blocks, floating or not, with different paddings and margins.
I don't really need the answer to a specific case, I'm just wondering if there are tools or tricks to quickly calculate such things.
Thanks

EDIT: Sorry to forget, this is on an external site where I can not install any scripts or edit the css.

+2  A: 

You can put JQuery to use and use its width() method for that. The jQuery is smart enough to get the computed width of the element you specify.

Sarfraz
see edit... not my site
Moak
@Moak: If you can not edit css or script and it is an external website you can not control, how can you be worried about getting elements' width, that's not possible :(
Sarfraz
I can add a limited amount of html inside the element, my intention is to put in 3 even sized/spaced fonts, and for that i need the exact pixels.
Moak
+3  A: 

jQuery has width() that allows to find out the width of any DOM element reliably across browsers. Does that help?

Pekka
sorry no, see edit...
Moak
Can you edit the html page itself? If so, you can do this. Refer to the hosted version of jquery.
Chris Farmer
It stands to reason, though, that using jQuery only for this is a bit overkill. I'd go with BalusC's answer instead.
Pekka
+3  A: 

You need to use element.offsetWidth.

var width = element.offsetWidth;
BalusC
It could be that I'm not really understanding the OP's question. If anybody can give some indication that this is the correct answer, I'll be happy to upvote :) (I didn't downvote either.) However, the OP can't use jQuery so you should get rid of the `$`.
Pekka
You were right, I confused `offsetWidth` with `clientWidth`.
BalusC
+7  A: 
David Dorward
+1 because OP seems to be indeed looking for a tool. OP should please be more clear next time. All our discussion for naught!
Pekka