mercredi 11 juillet 2018

jQuery if statement using URL that needs to do select all pages in section with exceptions

I'm not sure my title was the greatest but hopefully it makes sense.

I'm attempting to show or hide an element depending on the page that the user is on.

When they are on "foo" and its sub-pages I need the button to show however there are specific pages within the foo section ("foo/hey") that I need it to NOT show on.

The problem is that once it passes the first if statement the second is ignored.

Any help would be most appreciated.

$(function () {
  if (window.location.href.indexOf("foo") > -1) {
    console.log('button should show here');
  } 
  if (window.location.href.indexOf("foo/hey") > -1) {
    console.log('button should get hidden here');
  } 
  else {
    console.log('button should get hidden on any other page of the site');
  }
});

Aucun commentaire:

Enregistrer un commentaire