Skip to content

Instantly share code, notes, and snippets.

@chattago2002
Created November 23, 2023 16:10
Show Gist options
  • Select an option

  • Save chattago2002/232abc1a7a34e584c53f667b09405e47 to your computer and use it in GitHub Desktop.

Select an option

Save chattago2002/232abc1a7a34e584c53f667b09405e47 to your computer and use it in GitHub Desktop.
Remove current url from a list (as a menu)
jQuery(document).ready(function() {
updateItems(jQuery("#menu ul"));
})
// listEl is the menu/list element to be read.
// It could be a simple string or an array
function updateItems(listEl = null) {
if (!listEl) {
const currentUrl = jQuery(location).attr('href');
var listElArr = [];
if (typeof listEl === "string") {
listElArr.push(listEl);
} else {
listElArr = listEl;
}
listElArr.forEach((el) => {
jQuery(el).find("li").each(function(){
let url = jQuery(this).find('a').attr('href');
if (url.includes(currentUrl + '#')) {
url.replace(currentUrl,'');
jQuery(this).find('a').attr('href', url)
}
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment