I wrote a simple javascript code to find whether the string exists in innerHtml in selected elements, now I would like to hide element that contains that string but I'm not sure how to get the tag id or something to hide specified element. Here's my code.
function hideTemplateOption(collToHide, hideText) {
let collection = document.getElementsByClassName("product_tr_cus");
if(collectionContains(collection,"test")) {
console.log("contains");
} else {
console.log("nope");
}
}
function collectionContains(collection, searchText) {
for (var i = 0; i < collection.length; i++) {
if( collection[i].innerText.toLowerCase().indexOf(searchText) > -1 ) {
return true;
}
}
return false;
}
hideTemplateOption();
You can do
collection[i].style.display = 'none';
or better set it conditionally:it will hide the node that have the string if you want the opposite then use:
and you probably will need better name for the function as well.