If instead of using "document.getElementsByClassName", I use "document.getElementById" and assign an Id to it, in that case if it works, what am I doing wrong?
function resalta(elEvento) {
var evento = elEvento || window.event;
switch(evento.type) {
case 'mouseover':
this.style.borderColor = 'red';
break;
case 'mouseout':
this.style.borderColor = 'green';
break;
}
}
window.onload = function() {
document.getElementsByClassName("texto").onmouseover = resalta;
document.getElementsByClassName("texto").onmouseout = resalta;
}
.texto{
height:60px;
width: 150px;
border: solid green;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel=stylesheet href="css/estilos.css" type="text/css"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/codigo.js"></script>
<title>Document</title>
</head>
<body>
<div class="texto">¡¡¡ANUNCIO!!!</div>
</body>
</html>