javascript - Target all <a> elements with a certain textContent while no identifier is available -


i have webpage includes a tags want remove.

assuming these a tags have no identifier , suffice them identifiers end (not site):

how target these a elements through textcontent property?

i tried these codes:

  • the first brought undefined.
  • the second brought unexpected identifier.

what have missed js freshman?

code 1:

let texttoremove = [ "עריכה", "עריכת קוד מקור", "שיחה", "גרסאות קודמות", "מזנון", "כיכר העיר" ];  document.queryselectorall("a").foreach( e => {     if ( e.textcontent == texttoremove ) {         e.style.display = "none"     } }); 

code 2:

let strings = [ "עריכה", "עריכת קוד מקור", "שיחה", "גרסאות קודמות", "מזנון", "כיכר העיר" ];  let links = document.queryselectorall("a");  ( string strings) {     if ( links.textcontent == strings) {         link.style.display = "none";     } } 

the second syntax belongs php.

any way, first code have errors, first tried compare array string, instead of checking if array contain string.

2) compare operator == not =

3) put ) before } in end of function

working code:

let texttoremove = [ "עריכה", "עריכת קוד מקור", "שיחה", "גרסאות קודמות", "מזנון", "כיכר העיר" ];  document.queryselectorall("a").foreach( e => {     if (texttoremove.indexof( e.textcontent ) > -1 ) {     e.style.display = "none";     } });  

https://jsfiddle.net/hf3x5zb0/


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -