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

222
Views
Remove canonical links from dynamically generated pages

I want to remove a canonical tag from my website. It can't be removed directly from the website since the pages are created on the fly and there are hundreds of them. I want to remove them via tag manager but don't know what JS code to write. Can anyone help?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

/*
Here you should select elements you need to remove.
With the querySelectorAll, you will select the elements you want to remove.
Assume that we want to remove li elements with .red class in this example.
liList is a nodeList. So you can use foreach for iterating.
*/
let liList = document.querySelectorAll('.red');  

liList.forEach((currentLi) => {
    currentLi.remove(); //Removing all selected li elements
});
<html>
<body>
    <ul>
        <li class="red">List1</li>
        <p>Text1</p>
        <li class="red">List2</li>
        <p>Text2</p>
        <li class="red">List3</li>
        <p>Text3</p>
        <li class="red">List4</li>
        <p>Text4</p>
        <li class="red">List5</li>
    </ul>
</body>
</html>

What you need to do is to select the tags you want to remove with DOM operators. I leave a simple example here. All you have to do is make a querySelectorAll operation that suits your needs.

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!