RobG said:
David said:
RobG wrote:
nick wrote:
On May 9, 6:46 am, SAM wrote:
Le 5/9/10 8:49 AM, nick a écrit :
[...]
I'm working on another Chrome extension. I want to pop the dropdown
open when the user clicks its containing <label>.
<label onmouseover="dropDown(this)" for="select_1">
blah blah ... ... :
<select id="select_1"
onclick="dropUp(this); doThat(this)">
... ...
</label>
AFAIK you don't need the 'for' attribute if the control is inside of
the label
According to the W3C HTML specification, yes. But you presume all
browsers follow the spec.
You don't, but you should avoid that construct for compatibility reasons.
You do if the browser is IE 6, and maybe others.
As mentioned, best to avoid that construct altogether (that's what I
do). Then you can remain blissfully unaware of such idiosyncrasies (as
I am).
And actually, that's not quite accurate. The fact that IE6 ignores the
implications of that construct is an example of the incompatibilities I
advised to avoid. Without the - for - attribute, IE6 just doesn't make
the connection.
Yes, problem is that practices develop to avoid incompatibilities,
then after a while someone asks "why do we do that?" and everyone has
forgotten the answer.
The only answer for this one is that some browsers can't deal with that
construct. As for which browsers specifically; you are right, I
couldn't remember. Could be lots of them of course.
I don't know if there's any way to design around
that other than to fully document the code. Seems to be human nature.
Just use something like jQuery. It makes all browsers look exactly
alike.
Well, except for IE6, IE7, IE8 in its default Compatibility
View, older versions of FF, Opera, Safari, etc. Er, scratch that.
Don't use jQuery.
Another example is getting the value of a select element - most modern
browsers will give the correct answer where the type is select-one and
all options have a value attribute given:
alert( selectElement.value );
but some ancient browser didn't (Navigator 4 or 5?), so we persist
with the clumsy:
I don't think there was any NN5 (didn't it get canceled?) And I don't
think the issue is relegated to NN4 either, but am not sure.
alert( selectElement.options[selectElement.selectedIndex].value )
It is a good candidate for a wrapper function.
and even then some browsers still get it wrong if the option has no
value attribute, so there's the tiresome "if there's no value, get the
text" loop.
Yes, that is irritating (and I've seen many examples of "major" scripts
getting it wrong). Best to use values.
Then some bright spark asks "Why don't we use selectElement.value?
Works in all the (very small number of modern) browsers I tested
in...".
Sure, why not use complicated CSS3 queries? The libraries that call QSA
will likely get them right (some feat) in a handful of the latest
browsers. Of course, their fallback code likely won't so compatibility
goes out the window. I can't understand how the developers can ignore
the tons of users who browse from work (businesses aren't known to be
quick to upgrade software, particularly browsers). It's like their only
goal is to make shiny demos that "work" in the very latest browsers (the
ones they profess to "care" about anyway). How most of the world
figured it was a good idea to buy in to such thoughtless designs is
beyond me.
And then there is type select-multiple to contend with, which HTML 5
doesn't fix.
As far as I am concerned, HTML5 does not yet exist. I see people using
its doctype and wonder what they are thinking. Perhaps that they are on
the cutting edge? Maybe they just want to add another "skill" to their
resumes (at the expense of their clients).