Jump to content

Trying to Re-use Working Code on New Site - Active Nav


Recommended Posts

Hello,

 

I had some help here a little while ago on getting some code to work so that the buttons of the main navigation of the site reflected with page and/or section you are in/on.

 

I am trying to re-use the code on a new site and am running into some issues...mainly, it's not working.

 

The new site is here:

http://clarkwireless.oiw10.com

 

I ended up using this code to target all the "main/top layer" buttons:

 

<script> var current = window.location.href; if ( current == "http://clarkwireless.oiw10.com" || current == "http://clarkwireless.oiw10.com/" || current == "http://clarkwireless.oiw10.com/index.htm" ){ jQuery('#menu > li > a[href=/index.htm]')().addClass("active"); } else if ( current.indexOf("http://clarkwireless.oiw10.com/about-us/") > -1 || current.indexOf("http://clarkwireless.oiw10.com/news") > -1 || current.indexOf("http://clarkwireless.oiw10.com/resources") > -1 || current.indexOf("http://clarkwireless.oiw10.com/videos") > -1 || current == "http://clarkwireless.oiw10.com/contact-us.htm" ){ jQuery('#menu > li > a[href$=/about-us/index.htm]').parent().addClass("active"); }</script>

 

And I ended up using this code to catch the buttons in the drop downs:

<script> $(function () { setNavigation(); }); function setNavigation() { var path = window.location.pathname; path = path.replace(//$/, ""); path = decodeURIComponent(path); $("#menu a").each(function () { var href = $(this).attr('href'); if (path.substring(0, href.length) === href) { $(this).closest('li').addClass('active'); $('li.active').parents().not('ul').addClass('active'); } }); } </script>

 

I've tried a few things with the CSS and within the Javascript, but it's a little over my head.

 

Any help would be greatly appreciated!

 

m@

Link to post
Share on other sites

Hmm, I'm not really familiar with what to look for in the error console. But, I ran it on the site that the code it coming from (working); tfmcomm.com and I'm not seeing a difference.

 

My initial guess is that I'm missing something with the parent/child li and ul and/or something with the different id/class names???

 

But, yet again, that's why I'm here...

Link to post
Share on other sites

Anything marked in red in the error console is a problem. If you don't know what it means then put it here so we can tell you.

 

Do you have the jQuery library included on your page before your script?

Link to post
Share on other sites

I have the jQuery library included in the head. Then I have the above script following the menu. Does that answer anything.

 

If I'm doing things correctly, I'm seeing the same "error" in the console on both the site that the script is working (www.tfmcomm.com) and the site that I'm trying to get it to function on (http://clarkwireless.oiw10.com). Not. To. Sure...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...