Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda