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

197
Visualizações
Removing Div from Website only works the first time

I am trying to build an chrome extension for lichess.org to permanently remove some elements from the website.

As the elements (in this case divs) can reappear if the user navigates through the website, I implemented a MutationObserver to remove the divs again as soon as they get added again. However, even though the function to remove them is called and they don't change their data-id, they are only removed when the function is called for the first time.

This is what I've tried so far:

These are the divs I want to remove. They are exactly the same after reappearing.

const bullet1 = document.querySelector('[data-id="1+0"]');
const bullet2 = document.querySelector('[data-id="2+1"]');

This is the MutationObserver. The div gets added with the addedNode.

const parent_lobby = document.querySelector("#main-wrap > main");

const mutationObserver = new MutationObserver(mutations => {
   
    if (mutations[0].addedNodes[0].className == "lobby__app lobby__app-pools"){
        remove_bullet_QP();
    }
})

mutationObserver.observe(parent_lobby, {childList: true})

This is the function called to remove the elements. The first call of the method that happens as soon a the webiste is opened.

function remove_bullet_QP(){
    bullet1.remove();
    bullet2.remove();
}

remove_bullet_QP();

I've also tried to overwrite the divs before calling the function to remove them, but it didn't change the result.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Thanks for your help.

I changed bullet1 and bullet2 from const to let and reassigned them on each function call. This seems to work.

As I said in my question, I have tried reassign before, but without changing it to leave. This should have given me an error message, somehow it didn't.

about 4 years ago · Santiago Trujillo 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