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

172
Visualizações
How can I determine when a particular node has been mutated in the DOM?

I have a MutationObserver attached and I am getting mutation events. I can manually look through the events and see the node I am interested in being added and removed. However, I am having difficulty finding this information programmatically.

However, I believe I am close...

handleMutations( mutationsList, observer ) {
    // console.log( mutationsList );
  
    mutationsList.forEach( mutation => {
        mutation.addedNodes.forEach( node => {
            console.log( "added", node, typeof( node ) ) 

            let foundNode = ( node.id === "thediv" );
    
            if ( !foundNode ) {
              const child = node.querySelector( "#thediv" );
      
              if ( child ) {
                foundNode = true;
              }           
            }
    
            if ( foundNode ) {
              console.log( "found node. do something." );
            }
        });         
    }); 
},

The node I am interested in has the id thediv.

The problem is that I get nodes like:

added <!----> object

and I cannot call querySelector on it -- when I do, it simply crashes.

I am sure this is trivial, but how can I be certain I am dealing with a node which responds to querySelector?

about 4 years ago · Juan Pablo Isaza
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