I want to hide all element with tag and contain a link

前端 未结 2 1422
慢半拍i
慢半拍i 2021-01-29 10:34
2条回答
  •  情书的邮戳
    2021-01-29 10:37

    First of all, you are incorrectly using addEventListener. Second, you must check the href attribute, not innerHTML:

    window.addEventListener("yourEvent", () => {
      var elem=document.querySelectorAll("a");
      for(var i = 0; i < elem.length; i++) {
        if(elem[i].href.includes('sabdel.com')) {
          elem[i].style.display="none";
        }
      }
    }
    

    Replace yourEvent with the event you want to listen with. For example, if you are listening for a click event, replace it with click.

提交回复
热议问题