Skip to content

aschmelyun/active-links

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

active-links NPM version NPM downloads

🔗✨ Add classes to links if their href attribute matches the current url.

Useful on static websites as a visual indicator to show what page you're on.

Installation

$ npm install active-links --save

Usage

const activeLinks = require('active-links');

// supply a selector, and the class you want to add to the links matching the current url
activeLinks('nav a', 'is-active');

// alternatively, you can use an array for the classes
activeLinks('nav a', ['text-blue-500', 'border-b-2', 'border-blue-500']);

// you can also specify a list of classes to set on the rest of the inactive items, if you want
activeLinks('nav a', 'is-active', 'is-inactive');

Contributing

Pull requests and stars are welcome. Have an issue? Submit it here! Want to get in touch directly? Feel free to reach out to me on Twitter for any other questions or comments.

License

The MIT License (MIT). See LICENSE.md for more details.

About

Update link classes if their href matches the current url

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published