Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

wait until something happens javascript

//1st methode : not good enough : very slow

const poller=setInterval(()=>{
  //if you want use async function 
   // return new Promise((resolve, reject) => {

  let bear=document.querySelector('ul.bears li')
  if(bear){
    console.log(bear)
    clearInterval(poller)
   // resolve(bear)
  }
   // })
},2000)


//2sd methode : (we will use mutation observer)
const observer= new MutationObserver((mutations)=>{
  mutations.forEach((mutation)=>{
    if(mutation.addedNodes.lenght){
      console.log(mutation.addedNodes[0])
       }
    
  })
})
// the elelemtn you wanna to observe
const bears=document.querySelector('ul.bears')
observer.observe(bears,{childList:true})
Comment

PREVIOUS NEXT
Code Example
Javascript :: ng model on change 
Javascript :: react js pdf generate from html 
Javascript :: jquery code to make click function 
Javascript :: Contact form tutorial next.js 
Javascript :: reg ex with filter in js 
Javascript :: hcaptcha bypass 
Javascript :: remove element from array javascript by index 
Javascript :: javascript current target 
Javascript :: jquery fadeout to fadein 
Javascript :: process.env 
Javascript :: unidirectional data flow 
Javascript :: randomize an array in javascript 
Javascript :: javascript replace with UpperCase 
Javascript :: js compare elements of two arrays 
Javascript :: round value up javascript 
Javascript :: how to choose a random name from a list in javascript 
Javascript :: how to validate email in node js 
Javascript :: vue 3 router redirect 
Javascript :: react router dom change default path 
Javascript :: how to use filter in typescript 
Javascript :: website implement jquery in js 
Javascript :: how to write a json in r 
Javascript :: code that will execute at a certain day and time javascript 
Javascript :: javascript window 
Javascript :: set lodash 
Javascript :: how to make text channels in discord.js 
Javascript :: javascript newline to brake 
Javascript :: how to connect mysql using node js stack 
Javascript :: summation js 
Javascript :: js select last item in html list query selector 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =