Leo
Leo

Reputation: 315

Hide div if the URL has those words

I have this code, this works with a word, but i want to add multi words, example, "one", "two", "three" etc..

$(document).ready(function () {
    if(window.location.href.indexOf("one") > -1) {
       $( ".hideif" ).hide();
    }
});

some help thank you.

Upvotes: 0

Views: 125

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 371233

Use an array and see if some of the words in the array are .included in the href:

$(document).ready(function () {
    const words = ['one', 'two', three'];
    if (words.some(word => window.location.href.includes(word))) {
       $( ".hideif" ).hide();
    }
});

Upvotes: 2

Related Questions