Ver Mensaje Individual
  #10 (permalink)  
Antiguo 25/02/2013, 08:53
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: AddEventListener Problema al intentar capturar su Id

En referencia a tu objetivo
Código:
<div onmouseover="this.style.opacity = 1"> </div>
Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <title>addEvent + variable</title>
  3.  
  4. td{
  5. cursor: pointer;
  6. }
  7. div#uno{
  8. background: #000;
  9. opacity: .5;
  10. width:100px;
  11. height:100px;
  12. }
  13. // cambia opacidad
  14. function cambiaOpc(elem,v) {
  15. elem.style.opacity = v;  
  16. }
  17.  
  18. // agregar Evento
  19. window.onload = function(){
  20.   var el = document.getElementById("uno");
  21.   el.addEventListener("mouseover", function(){cambiaOpc(el,'1')}, false); // pasas el objeto como parámetro a la función
  22. }
  23.  </head>
  24.   <div id="uno"></div>
  25. </body>
  26. </html>

o bien le ponés un id al div, ó lo identificas de alguna otra manera,
Código:
document.getElementsByTagName('div')[0];
por ejemplo

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.