How to use Tampermonkey to remove from the page any div that has href="/66666" in the code?

Viewed 56

Code:

<div id="a787656" class="a r">
  <a class="p online" href="/66666" rel="author nofollow" itemscope="" itemtype="http://schema.org/Person">
    <img src="https://m.photo.com" width="64" height="64" alt="Noname" itemprop="image" loading="lazy">    <div class="name" itemprop="name">Noname</div>
  </a>
  <div class="cont">
    <p style="background:#e8f4eb" data-href="/a/787656">Yes</p>

I already tried deleting everything with document.getElementsByName but it didn't work.

1 Answers

The selector you are after is [href='/66666'] and the universal method for this kind of things is querySelectorAll (or querySelector).

document.querySelectorAll("[href='/66666'], p[style]").forEach(function(elem) {
  elem.remove();
})
<div id="a787656" class="a r">
  <a class="p online" href="/66666" rel="author nofollow" itemscope="" itemtype="http://schema.org/Person">
    <img src="https://m.photo.com" width="64" height="64" alt="Noname" itemprop="image" loading="lazy">
    <div class="name" itemprop="name">Noname</div>
  </a>
  <div class="cont">
    <p style="background:#e8f4eb" data-href="/a/787656">Yes</p>
    
    i'm last
    

Related