Lightweight DOM Utility

2.0.0 · abandoned · verified Tue Apr 21

Bonzo is a library-agnostic, extensible DOM manipulation utility designed to be minimalist and work with or without a host library like Ender.js. It provides a chainable API for common DOM tasks such as adding/removing classes, manipulating CSS, appending/prepending elements, and iterating over collections. Version 2.0.0, published in 2012, is the latest release and the package has been largely unmaintained since then. It differentiates itself from larger libraries like jQuery by focusing solely on DOM manipulation and explicitly requiring integration with external selector engines (e.g., Qwery) for CSS-style selections, rather than including one internally. Its release cadence was irregular, and it is now considered abandoned.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic DOM manipulation using Bonzo's chainable API, including class manipulation, CSS styling, element insertion, and extending Bonzo with a custom method. It shows how to work with elements directly as Bonzo does not include a selector engine.

// This example demonstrates basic DOM manipulation using Bonzo,
// typically combined with a selector engine like Qwery.
// As Bonzo is a global or CommonJS export, we simulate its availability.

// In a browser, Bonzo might be available globally:
// <script src="path/to/bonzo.js"></script>

// For demonstration, let's assume 'bonzo' is available.
// In a real scenario, if using CommonJS:
// const bonzo = require('bonzo');

const elements = [
  document.createElement('div'),
  document.createElement('p')
];

elements[0].id = 'bonzo-container';
elements[1].textContent = 'Hello from Bonzo!';
document.body.appendChild(elements[0]);
elements[0].appendChild(elements[1]);

bonzo(elements[0])
  .hide() // Initially hide the element
  .addClass('bonzo-managed-element')
  .append('<span>Appended content with Bonzo!</span>')
  .css({
    color: 'darkgreen',
    'font-size': '16px',
    'border': '1px dashed #ccc'
  })
  .show() // Then show it with new styles and content
  .after('<div class="sibling-element">I am a sibling added after.</div>');

// You can also extend Bonzo with custom methods:
bonzo.aug({
  highlight: function (color) {
    return this.css('background-color', color || 'yellow');
  }
});

// Now use the custom method
bonzo(elements[1]).highlight('lightblue');

console.log('Bonzo operations complete, check the DOM!');

view raw JSON →