Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
Javascript : Why can't I use the "this" with childnodes?
<div id="test" onmouseover="working(this)">
<p>help</p>
<p>me</p>
</div>

<div id="test" onmouseover="not_working(this)">
<p>help</p>
<p>me</p>
</div>

When I use the first function(not_working) it doesn't work, but when I used the second function(working) it does.

function not_working(element){
document.getElementById(element).childNodes[1].innerHTML="succeed";}

function working(element){
document.getElementById("test").childNodes[1].innerHTML="succeed";}

Sorry if I miss something simple, I'm still learning html and only have limited knowledge on javascript.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

this is a reference to the element, the event was created from (the div in your case), but getElementById takes an id ("test" in your case).

Also the hovered element is already being passed in the function as element so you can just do:

function working(element) {
    element.childNodes[1].innerHTML="succeed"
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda