Answers for "check if text contains certain text in javascript"

3

javascript check if string contains a text substring

stringVariable.includes("Your Text");
Posted by: Guest on November-22-2020
0

find element that has certain text javascript

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))
Posted by: Guest on October-28-2021

Code answers related to "check if text contains certain text in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language