Skip to content

Instantly share code, notes, and snippets.

@ubarbaxor
Created December 12, 2017 13:54
Show Gist options
  • Save ubarbaxor/b40dcc1b16a4198ec34df46d7316f970 to your computer and use it in GitHub Desktop.
Save ubarbaxor/b40dcc1b16a4198ec34df46d7316f970 to your computer and use it in GitHub Desktop.
Fix for navbar on france-digital-expert.com

Header Nav's seem not to work due to two things :

1/ Underlying anchors' href property doesnt concur with sections' classes 2/ Clicking the section doesn't seem to toggle the anchors

This is all probably caused by a faulty JQuery manipulation.

Proposed solution :

On nav click, get underlying anchor's href, correct it, and set it as location

Tested on Chrome 62.0.3202.94

Long live the buzzwords #digital

// Get all elements from the menu
const listElems = [
// Destructure / restructure on-the-fly to get an iterable array instead of a nodeList
...document.getElementsByClassName(
'menu-item menu-item-type-post_type menu-item-object-page')
]
// Fix each node
listElems.forEach(navElem => {
// Since they don't click through, bind click on them
navElem.onclick = () => {
// Set window location on click
window.location = navElem.firstChild
// Since href's are wrong, fix them on-the-fly
.href.replace('section-', '')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment