Skip to content

Instantly share code, notes, and snippets.

@fagci
Last active October 11, 2022 19:02
Show Gist options
  • Save fagci/014739a21f59c02f899324b95c55f8c2 to your computer and use it in GitHub Desktop.
Save fagci/014739a21f59c02f899324b95c55f8c2 to your computer and use it in GitHub Desktop.
Untitled
.active {
font-weight: bold;
color: red;
}
<div id="nav1">
<a href="https://dabblet.com/gist/111">Not Current</a>
<a href="https://dabblet.com/gist/014739a21f59c02f899324b95c55f8c2">Current</a>
</div>
<div id="nav2">
<a href="https://dabblet.com/gist/222">Not Current</a>
<a href="https://dabblet.com/gist/014739a21f59c02f899324b95c55f8c2">Current</a>
</div>
const links = document.querySelectorAll("#nav2 a");
const linksCount = links.length;
console.log(links);
for (let i = 0; i < linksCount; i++) {
console.log(123)
if (window.location.href.startsWith(links[i].href)) {
links[i].classList.add("active");
}
}
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"javascript"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment