Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!