Skip to content
A dead simple JavaScript library for automatically creating anchored headings in your HTML documents.
JavaScript CSS
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist Fix getText method to deal with nestes nodes, e.g. span inside header
src
tests
.travis.yml Add travis-ci stuff
LICENSE
README.md Fix special character
anchorify.jquery.json
bower.json

README.md

Anchorify.js

Build Status

Anchorify.js is a dead simple JavaScript library for automatically creating anchored headings in your HTML documents. It guarantees uniqueness of the anchor names, and is able to reuse existing ids.

It can be used either as a jQuery plugin, or as a standalone library without any dependencies (except querySelectorAll()).

Usage

It could not be easier as Anchorify.js provides a jQuery plugin out of the box:

$('h2 h3').anchorify();

Anchorify.js generates clean anchor names:

<h2>Hello, World!</h2>
<!-- would become: -->

<h2 id="hello-world">Hello, World!<a href="#hello-world" class="anchor-link">¶</a></h2>

By default, it uses the sign for the links' text, and adds an anchor-link CSS class on each link.

However, you can configure your own text, CSS class and anchor position using the text, cssClass and position options:

$('h2').anchorify({ text: 'Hey', cssClass: 'anchor', position: 'prepend' });
<h2 id="hello-world"><a href="#hello-world" class="anchor">Hey</a>Hello, World!</h2>

Running the Tests

Open the tests/index.html file in your browser or use PhantomJS:

phantomjs tests/run-qunit.js file:///.../anchorify.js/tests/index.html

License

Anchorify.js is released under the MIT License. See the bundled LICENSE file for details.

Something went wrong with that request. Please try again.