active-links

1.0.1 • Public • Published

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.

Package Sidebar

Install

npm i active-links

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

4.39 kB

Total Files

4

Last publish

Collaborators

  • aschmelyun