Created
November 23, 2023 16:10
-
-
Save chattago2002/232abc1a7a34e584c53f667b09405e47 to your computer and use it in GitHub Desktop.
Remove current url from a list (as a menu)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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