📌  相关文章
📜  查找具有特定文本的元素 javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:28.331000             🧑  作者: Mango

代码示例1
for (const a of document.querySelectorAll("a")) {
  if (a.textContent.includes("your search term")) {
    console.log(a.textContent)
  }
}

Or with a separate filter:

[...document.querySelectorAll("a")]
   .filter(a => a.textContent.includes("your search term"))
   .forEach(a => console.log(a.textContent))