Suppress errors when nav does not exist on page #181

Open
cherrmms opened this Issue Oct 9, 2015 · 1 comment

Projects

None yet

2 participants

@cherrmms
cherrmms commented Oct 9, 2015

We are pulling in the responsive nav script globally for our site. However some pages do not contain a navigation element. Therefore errors are thrown due to the fact that the nav does not exist. How do I suppress the errors for pages that do not contain the nav?

Many Thanks!

@Aybee
Aybee commented Oct 9, 2015

Error is thrown by this line https://github.com/viljamis/responsive-nav.js/blob/master/responsive-nav.js#L235

I think this is not bad, or am I wrong?

You can suppress the init of your navigation by

if(document.getElementsByClassName('nav-collapse').length > 0) {
  var navigation = responsiveNav(".nav-collapse");
}

But then I think you also shouldn't load the responsive-nav.js to save resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment