Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda