Skip to content

Instantly share code, notes, and snippets.

@prappo
Last active March 1, 2021 17:22
Show Gist options
  • Save prappo/1b838efacf70277108e40029560e182d to your computer and use it in GitHub Desktop.
Save prappo/1b838efacf70277108e40029560e182d to your computer and use it in GitHub Desktop.
menu items active based on hash url
jQuery(document).ready(function() {
if (/Android|webOS|iPhone|iPad|Mac|Macintosh|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
function setActive() {
setTimeout(function() {
var hash = window.location.hash.substr(1);
if (hash) {
jQuery('[href*="#"]').removeClass('elementor-item-active');
jQuery('[href*="' + hash + '"]').addClass('elementor-item-active');
}
}, 15);
}
setActive();
jQuery('[href*="#"]').click(function() {
var url = jQuery(this).attr('href');
window.location.hash = url;
setActive();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment