I have been looking through all the popular js libraries, but I cannot find one that has a width function for the DOM element that actually takes into account the quirks mode in Internet Explorer. The problem is that padding and borders are not counted in width when quirks mode is enabled. As far as I can tell, this happens when doctype is not taken into account, or doctype is installed in html 3.2.
Obviously, I could just set doctype to standards, but this script can be implemented anywhere, so I can't control doctype.
To break the problem into smaller parts:
1) How do you detect fad mode? 2) What is the best way to extract border and padding from an element for compensation?
An example with a prototype:
<html> <head> </head> <body> <div id="mydiv" style="width: 250px; pading-left: 1px; border: 2px black solid">hello</div> <script> alert($('mydiv').getWidth()) </script> </body> </html>
result:
253 (ff) 250 (i.e.)
Thanks in advance!
javascript html css
christoff
source share