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

174
Visualizações
How to run code when a dom element is added firefox extensions

I am making a extension that edits a element on a page but its only working if the element is on the page when it loads (with the website im using it will never happen) so i want to get a event if a div with the id of "427" shows up.

code:

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 Respostas
Responde à pergunta

0

You could use MutationObserver, but you should be careful with memory usage:

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})

You could also use Promise, by querying each 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 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