Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnajman committed Nov 16, 2023
1 parent 5a1a951 commit 5893c87
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ Go to any page and the primary menu link for that page will be highlighted. You
The JavaScript function checks to see if the `link.href` matches the `location.href`. If it does, the attribute `aria-current="page"` is set on the link. To cover the situation when the `location.href` is only `/` a further check is made:

```JavaScript
if (link.pathname === "/index.html" && location.pathname === "/")
if (
link.pathname.split("/").pop() === "index.html" &&
location.pathname.split("/").pop() === ""
)
```

If this is true, the attribute is set on the 'Home' link.

**Notes**
##### Notes

- The 'Home' page file name is `index.html`. If you decide to change it (e.g. `home.html`) you will have to update the reference to it in the JavaScript.
- The function is placed in a module and imported and called (`document.body.onload = setCurrentPageMenuItem()`) in `index.js`.
- **Important**: the function only works on a flat, top-level menu. It doesn't work if there are sub-folders containing an `index.html` page.

#### CSS

Expand All @@ -35,7 +39,7 @@ The `aria-current="page"` attribute is referenced in `primary-navigation.css`:
}
```

**Note**
##### Note

- CSS Nesting is used in this project.

Expand Down

0 comments on commit 5893c87

Please sign in to comment.