Reputation: 13
can someone help me with this.
I know this is pretty simple but I can't make this work.
I'm trying to hide some lines on my website that contains specific texts (shouldNotAppear). What I've done so far is in the code below, but it's not working. The best I could I do was doing it with .remove() but it messes with the array.
var shouldNotAppear = ['text1', 'text2', 'text3'];
for (var i in $(".brand li h4 .option-title")) {
if (shouldNotAppear.indexOf($(".brand li h4 .option-title")[i].innerText) != -1) {
$(".brand h4")[i].hide();
};
Upvotes: 0
Views: 105
Reputation: 24965
var shouldNotAppear = ['text1', 'text2', 'text3'];
$('.brand li h4 .option-title')
// filter to only the titles that have a value that should not appear
.filter(function(){ return shouldNotAppear.includes(this.innerText); })
// for each title that should not appear, go up to their parent h4
.closest('h4')
// hide them
.hide();
Upvotes: 1