Get started with NestedUl

Lightweight JavaScript library for rendering tree structures using standard nested HTML lists (ul > li > ul). No dependencies, minimal setup.

npm version downloads license

Installation

npm install nestedul

Usage

NestedUl works with a standard HTML nested list structure.

Basic HTML setup

Create a nested list with the nestedul class:

<ul class="nestedul">
  <li>
    Root
    <ul>
      <li>Child</li>
      <li>Child</li>
    </ul>
  </li>
</ul>

Import usage

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()
})

Script tag usage

<link rel="stylesheet" href="nestedul.css">

<script src="nestedul.iife.js"></script>

<script>
  document.addEventListener("DOMContentLoaded", function () {
    NestedUl.activate()
  })
</script>

API

activate(root)

Initializes all .nestedul lists inside the specified container. Default root is document.

NestedUl.activate()

Or inside a specific container:

NestedUl.activate(document.querySelector("#container"))

destroy()

Removes event listeners and deactivates the library.

NestedUl.destroy()

version

Returns the current library version.

console.log(NestedUl.version)

Why NestedUl

License

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.