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"; } });
Comments
Post a Comment