
Originally Posted by
benniaustin
If I recall, IE7 suppots :hover pseudoclasses on anything.
Yes, it does.
IE7 will be dominant over IE6, I'm guessing by the end of january.
Maybe. Maybe several years from now.
IE 7 is not available for all Windows platforms, and far from every Windows user uses WinXP SP2 or later. There are still plenty that use WinXP and WinXP SP1, as well as earlier operating systems: NT, '98, ME, 2000 - probably even '95 and 3.1, in a few dwindling cases. Whether WinXP SP2, Windows Server 2003, and Vista will outnumber those others remains to be seen. Even if they do, older operating systems will continue to be a significant minority.
Code:
function changeClass(myElementID) {
if(document.getElementById(myElementID).className == "basicRow") {
document.getElementById(myElementID).className = "highlightRow";
}
else {
document.getElementById(myElementID).className = "basicrow";
}
}
That's rather inefficient, and using two class names is a little much. One needn't obtain a reference more than once.
Code:
function changeClass(id) {
var element;
if (document.getElementById && (element = document.getElementById(id)))
element.className = (element.className == 'highlight') ? '' : 'highlight';
}
That said, it would be better behaved if it didn't interfere with other potential class names:
Code:
function toggleClassName(id, className) {
var classPattern = new RegExp('(^|\\s)' + className + '(\\s|$)'),
element;
if (document.getElementById && (element = document.getElementById(id)))
if (classPattern.test(element.className))
element.className = element.className.replace(classPattern, ' ');
else element.className += ' ' + className;
}
Code:
<tr class="basicRow" id="Row1" onmouseover="changeClass(Row1)" onmouseout="changeClass(Row1)">
Run-time error aside, there's little point in passing an identifier to then obtain a reference, when a reference can be passed directly:
Code:
function toggleClassName(element, className) {
var classPattern = new RegExp('(^|\\s)' + className + '(\\s|$)');
if ((typeof element == 'string') && document.getElementById)
element = document.getElementById(element);
if (element)
if (classPattern.test(element.className))
element.className = element.className.replace(classPattern, ' ');
else element.className += ' ' + className;
}
HTML Code:
<tr onmouseover="toggleClassName(this, 'highlight');"
onmouseout="toggleClassName(this, 'highlight');">
Mike
Bookmarks