1.0.1 • Published 3 years ago

active-links v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

active-links NPM version NPM downloads

:link::sparkles: 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.