I need to hide span elements if they match words in a 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 done correctly, it should hide 'hello' and 'you', but not 'hi'
If I do match('hello')
, this correctly hides 'hello' span from the HTML element list.
But I need to loop through each span element in wordBank_Words
, and compare them against each word in the wordList, and only hide if there is a match. They need to be compared regardless of order.
How can this be done?