I need to hide span elements if they match words in wordList.
HTML:
<span class="wordBank_Words">
<span word="hello"></span>
<span word="you"></span>
<span word="hi"></span>
</span>
JavaScript:
wordList = ['hello', 'how', 'are', 'you'];
$('.wordBank_Words span').each(function (index, val) {
if ($(this).attr('word').match(wordList)) {
$(this).hide();
}
});
So, if everything is done correctly, it should hide "hello" and "you", but not "hello"
If I do match('hello')
, this correctly hides the "hello" span from the list of HTML elements.
But I need to scroll through each span in wordBank_Words
and compare them with every word in the list of words, and only hide if there is a match. They need to be compared regardless of order.
How can I do that?
source
share