Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/firstandthird/toc-anchor
Automatically adds anchors to elements
https://github.com/firstandthird/toc-anchor
Last synced: 3 days 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 (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-01T12:07:43.000Z (over 5 years ago)
- Last Synced: 2024-12-29T04:29:28.212Z (25 days 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 ![npm](https://img.shields.io/npm/v/toc-anchor.svg) [![Build Status](https://travis-ci.org/firstandthird/svg-injector.svg?branch=master)](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', '');
```