On 08/07/2005 07:28, ASM wrote:
[snip]
IE is not reactive with this ccs rule :
td { color: blue }
td:hover { color: red }
IE is deficient and doesn't recognise the hover pseudo-class on any
elements except A.
if(document.all) being digested by others browsers than IE
which detection have I to place in my code in this case ?
You don't perform any detection at all, at least in the sense of looking
for IE. What you're looking for is specific behaviour, and then an
alternative method of achieving what you want.
var collection;
/* If gEBTN is supported, attempt to use it. */
if(document.getElementsByTagName) {
collection = document.getElementsByTagName('*');
}
/* If the previous attempt failed... */
if(!collection || !collection.length) {
/* Check to see if we can use the all property
* to obtain a collection of all elements in
* the document.
*
* Note that this is *not* a check for IE, but
* a feature test.
*/
if(document.all) {
collection = document.all;
/* If not, return an empty array as failure. */
} else {
collection = [];
}
}
More self-contained (but much more complex):
var getByTagName = (function() {
function isGenericObject(value) {
return isObject(value) || ('function' == typeof value);
}
function isObject(value) {
return !!value && ('object' == typeof value);
}
function tryDOM(a, tN) {
var e = useDOM(a, tN);
if('*' == tN) {
if(e.length) {
this.getByTagName = useDOM;
} else {
e = useTags(a, tN);
if(e.length) {this.getByTagName = useTags;}
}
}
return e;
}
function useDOM(a, tN) {
return a.getElementsByTagName(tN);
}
function useEmpty() {return [];}
function useTags(a, tN) {
return ('*' == tN) ? a.all : a.all.tags(tN);
}
return function(a, tN) {
this.getByTagName = isGenericObject(a.getElementsByTagName)
? isObject(a.all) && isObject(a.all.tags)
? tryDOM
: useDOM
: isObject(a.all) && isObject(a.all.tags)
? useTags
: useEmpty;
return this.getByTagName(a, tN);
};
})();
What you'd use depends on whether you'd end up repeating code. The above
really boils down to something quite simple and efficient, though it may
not look like it at first glance.
Mike