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

200
Views
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 answers
Answer question

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 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!