I want to add an "addEventListener" on all elements with the "object" class and that when the mouse goes over to change the edge of the object.
But I always select the last element in the loop.
There“s the code:
<div class='objeto' id='obj1'>obj1</div>
<div class='objeto' id='obj2'>obj2</div>
<div class='objeto' id='obj3'>obj3</div>
<script type='text/javascript'>
    var i;
    var objetos = document.getElementsByClassName('objeto');
    for (i = 1; i<objetos.length+1; i++){
         id = 'obj'+i; 
         document.getElementById(id).addEventListener('mouseover',function(){
                  borderObject(id);
         }, false);
    };
    function borderObject(id){ document.getElementById(id).style.border="4px solid red"; }
</script>
PD: I know that CSS exists: hover but I want to do it with Javascript
 
     
     
    