jQuery in Action
Using the jQuery flags
161
Not to belabor the point, it's important to once again note that this method of
branching (browser detection) is far from optimal. The code that we wrote
assumes that all non-Internet Explorer browsers will follow the
assumes that all non-Internet Explorer browsers will follow the
W3C
standard for
the
add()
method to the
<select>
element. With testing, we've determined that
this is true of the five non-Internet Explorer browsers depicted in figure 6.1 but
what of other browsers? Would you know how Konqueror works without testing?
what of other browsers? Would you know how Konqueror works without testing?
The bottom line is that because browser detection is such a broad brush, it
requires thorough investigation of any browsers and platforms we wish to support
with our code to know which branch a particular browser should take.
with our code to know which branch a particular browser should take.
Leaving the subject of browser detection behind, let's move on to another flag
that helps us deal with browser differences.
6.1.2 Determining the box model
Which box model the current page is using is available via the Boolean
$.boxModel
flag, which is set to
true
if the page is using the
W3C
standard box model and
false
if the page is using the Internet Explorer box model (sometimes called the
traditional box model).
"What's the difference?" you may ask.
The box model determines how the size of the content of an element is deter-
The box model determines how the size of the content of an element is deter-
mined in conjunction with its padding and border (margins, although part of the
box model, take no part in determining the content size). Most browsers, other
than Internet Explorer, support only the
box model, take no part in determining the content size). Most browsers, other
than Internet Explorer, support only the
W3C
box model, whereas Internet
Explorer can use either model depending upon whether the page is being
rendered in strict mode or quirks mode. Which mode is used depends upon the
rendered in strict mode or quirks mode. Which mode is used depends upon the
DOCTYPE
(or lack thereof) declared for the page being rendered.
It's beyond the scope of this book to go into a detailed examination of the var-
ious
DOCTYPE
issues, but some rules of thumb that work most of the time are
Pages with a valid and recognized
DOCTYPE
declaration are rendered in
strict mode.
Pages lacking a
DOCTYPE
declaration or those containing an unrecog-
nized declaration are rendered in quirks mode.
If you want to dig deeper into the
DOCTYPE
issues, an excellent resource to con-
sult is http://www.quirksmode.org/css/quirksmode.html.
In a nutshell, the difference between the two box models centers on how the
width
and
height
styles are interpreted. In the
W3C
box model, these values deter-
mine the dimensions of the content of the element, not counting its padding and