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

172
Views
Cómo ejecutar código cuando se agrega un elemento dom extensiones de Firefox

Estoy creando una extensión que edita un elemento en una página, pero solo funciona si el elemento está en la página cuando se carga (con el sitio web que estoy usando, nunca sucederá), así que quiero obtener un evento si un div con la identificación de "427" aparece.

código:

 var card = !!document.getElementById(427); console.log(card); if (card = true) { var card = document.getElementById(427) var cardimg = card.children.item(9) cardimg.setAttribute("style", 'background: transparent url("images/cards/Ultimate_Recipe.png") no-repeat scroll 0% 0%;') };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podría usar MutationObserver , pero debe tener cuidado con el uso de la memoria:

 const onMutation = () => { const element = document.getElementById(427) if (element) { observer.disconnect() elementIsReady(element) } } const observer = new MutationObserver(onMutation) observer.observe(document.body, {childList: true, subtree: true})

También podría usar Promise , consultando cada x ms:

 new Promise(async (resolve) => { let element while (!(element = document.getElementById(427))) await new Promise(r => setTimeout(r, 200)) resolve(element) }).then(elementIsReady)
about 4 years ago · Juan Pablo Isaza Report
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!