library agnostic, extensible DOM utility
Switch branches/tags
Nothing to show
Pull request Compare This branch is 243 commits behind ded:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


a simple, to the point, hassle-free, small (2.8k), library agnostic, extensible DOM utility. Nothing else. Bonzo is designed to live in any host library, or simply as a stand-alone tool for the majority of your DOM-related tasks.

It looks like this

  .append('<p>the happs</p>')
    color: 'red',
    'background-color': 'white'

Paired with a Selector Engine

A great way to use Bonzo is with a selector engine (like Qwery for example). You could wrap bonzo up and augment your wrapper to inherit the same methods. That looks like this:

function $(selector) {
  return bonzo(qwery(selector));

This now allows you to write the following code:

$('#content a[rel~="bookmark"]').after('').css('text-decoration', 'none');

Bonzo Extension API

One of the greatest parts about Bonzo is its simplicity to hook into the internal chain to create custom methods. For example you can create a method called color like this:

  color: function (c) {
    return this.css('color', c);

// you can now do the following

All other API methods

  • each
    • function (element, index)
  • map
    • function (element, index)
    • reject
  • html
    • html() get
    • html(str) set
  • text
    • text() get
    • text(str) set
  • addClass
  • removeClass
  • hasClass
  • show
  • hide
  • first
  • last
  • next
  • previous
  • append
  • appendTo(target)
  • prepend
  • prependTo(target)
  • before
  • insertBefore(target)
  • after
  • insertAfter(target)
  • css
    • css(prop) get
    • css(prop, val) set
    • css({properties}) set
  • offset()
    • offset(x, y) set
    • offset() get
      • top
      • left
      • width
      • height
  • attr
    • attr(k) get
    • attr(k, v) set
    • attr(obj) set
  • val
    • val() get
    • val(s) set
  • remove
  • empty
  • detach
  • scrollLeft
  • scrollTop
  • bonzo.aug({ properties })
  • bonzo.doc()
    • width
    • height
  • bonzo.viewport()
    • width
    • height
  • bonzo.isAncestor(container, child)
  • bonzo.noConflict

Added in the Ender bridge

  • parents(selector)
  • closest(selector)
  • siblings()
  • children()

Setting a query engine host

For the insertion methods you can set a query selector host (like qwery).

bonzo(bonzo.create('div')).insertAfter('.boosh a');

The name Bonzo

Bonzo Madrid was a malicious battle school commander of whom eventually is killed by Ender Wiggin. Bonzo represents the DOM, of whom we'd all love to slay.


Aside from simply downloading the source, if you would like to contribute, building Bonzo requires GNU 'make' and Node >= 0.4, and of course, git. The rest is easy:

$ git clone git:// bonzo
$ cd !$
$ git submodule update --init
$ make

make will run the JSHint linter as well as the Uglify compliler.


$ open bonzo/tests/tests.html

Ender integration

Bonzo is a registered npm package and fits in nicely with the Ender framework. If you don't have Ender, you should install now, and never look back, ever. As a side note the query engine host is set for you when you include it with Ender.

$ npm install ender -g

To combine Bonzo to your Ender build, you can add it as such:

$ ender build bonzo[,modb, modc,...]

or, add it to your existing ender package

$ ender add bonzo