Lightweight JavaScript library for rendering tree structures using standard nested HTML lists (ul > li > ul). No dependencies, minimal setup.
npm install nestedul
NestedUl works with a standard HTML nested list structure.
Create a nested list with the nestedul class:
<ul class="nestedul">
<li>
Root
<ul>
<li>Child</li>
<li>Child</li>
</ul>
</li>
</ul>
For Webpack, esbuild, Vite, Rails jsbundling, etc.:
import NestedUl from "nestedul"
NestedUl.activate()
If your project uses Turbo (for example Rails):
import NestedUl from "nestedul"
document.addEventListener("turbo:load", () => {
NestedUl.activate()
})
<link rel="stylesheet" href="nestedul.css">
<script src="nestedul.iife.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
NestedUl.activate()
})
</script>
Initializes all .nestedul lists inside the specified container. Default root is document.
NestedUl.activate()
Or inside a specific container:
NestedUl.activate(document.querySelector("#container"))
Removes event listeners and deactivates the library.
NestedUl.destroy()
Returns the current library version.
console.log(NestedUl.version)
ISC License — Copyright © Zlatov
Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.