https://github.com/firstandthird/toc-anchor
Automatically adds anchors to elements
https://github.com/firstandthird/toc-anchor
Last synced: 4 months ago
JSON representation
Automatically adds anchors to elements
- Host: GitHub
- URL: https://github.com/firstandthird/toc-anchor
- Owner: firstandthird
- License: mit
- Created: 2017-11-13T12:10:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-01T12:07:43.000Z (about 6 years ago)
- Last Synced: 2025-03-04T09:40:28.028Z (4 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TOC-Anchor  [](https://travis-ci.org/firstandthird/toc-anchor)
Automatically adds anchors to elements.
## Installation
```sh
npm install toc-anchor
```## Usage
In your project import the library:
```js
import TocAnchor from ‘toc-anchor’;
```Import [default styles](styles.css).
### TocAnchor(selector, [anchorContent])
Initializes anchor library. Both the first and second argument can either be a selector, DOM node, or a collection of DOM Nodes.
#### Parameters
`selector` _{string|Element|NodeList}_ - Selector to which anchors will be added
`[anchorContent]` _{string|Element|NodeList}_ - Content to be included as anchor, if no provided a clip icon will be added by default
#### Returns
`Array` - Array containing the elements to which anchors where added
## Example
```js
const els = TocAnchor('.my-class h1', '');
```