62e287602083a5ce1c570a60ee1823543910dac9
A plugin that generates table of contents(TOC) automatically for both jQuery or non-jQuery.
Install
bower install jquery-toc
Compatibility
- non-jQuery version works on IE9+
- jQuery version works on anywhere with jQuery
Showcase
https://idiotwu.me/understanding-es6-promise/
Usage
non-jQuery
// returns an ordered-list of headers in page content
var list = initTOC(options);
// then you can append it to anywhere you like
container.appendChild(list);
jQuery
// will append TOC list to target element
$(elem).initTOC(options);
Options
initTOC({
selector: 'h1, h2, h3, h4, h5, h6',
scope: 'body',
overwrite: false,
prefix: 'toc'
})
String:selector: headers selector, default is'h1, h2, h3, h4, h5, h6'.String:scope: selector to specify elements search scope, default is'body'.Boolean:overwrite: whether to overwrite existed headers' id, default isfalse, which means plugin will preserve the existed id property and create a string liketoc-1for those don't have id assigned.String:prefix: string to prepend to id/href property, default is'toc', which generates a string liketoc-0.
License
MIT.
Languages
JavaScript
60.4%
HTML
39.6%