Vulkan, все проще, ваш вариант не кроссбраузерный:
<script type="text/javascript">
window.onload = function() {
var getElementsByClassName = function(getClass){
if(document.querySelectorAll) {
return document.querySelectorAll("." + getClass);
}
else if(document.getElementsByClassName) {
return document.getElementsByClassName(getClass);
}
else {
var list = document.getElementsByTagName('*'), i = list.length,
classArray = getClass.split(/\s+/), result = [];
while(i--) {
if(list[i].className.search('\\b' + classArray + '\\b') != -1) {
result.push(list[i]);
}
}
return result;
}
};
var handler = ['mouseover','mouseout'], i = handler.length;
while(i--) {
getElementsByClassName('class')[0]['on'+handler[i]] = function () {
this.style.color = this.style.color == '' ? '#ff0000' : '';
}
}
};
</script>
<a href="#" class="class">ссылка</a>