Here is the JSFiddle so you can play with it: http://jsfiddle.net/9nr4Y/
HTML:
<div class="login">Login</div>
<br />
<div class="login">Login 2</div>
JavaScript:
(function() {
var elms = document.getElementsByClassName("login"),
l = elms.length, i;
for( i = 0; i < l; i++ ) {
( function( i ) {
elms[i].onmouseover = function() {
this.style.color = "#000000";
this.style.background = "#FFFFFF";
};
})(i);
( function( i ) {
elms[i].onmouseout = function() {
this.style.color = "#FFFFFF";
this.style.background = "#000000";
}
})(i);
}
})();
Create a self-invoking function that then gets the elements by a class name. The reason for this is because you don't really want to have more than one element with the ID anyway. Getting the class name will generate an Array of items that have that class. Then you can iterate over the new array and assign the event to each one of them.
Then we're getting each individual element with "this" instead of the actual event.
For reference:
How to get current element in getElementsByClassName