Software Development and Training

Master Controller

The buttons below control which section of the page below is "active".

This page uses active delegating and jQuery to establish delegating event handlers on a container. The event handling can be turned off or on by adding or removing a class on the container, rather than by removing/adding the handlers repeatedly.

$(document).ready(function() {
  $('#controller').on('click', '.liButton', function() {
    var $this = $(this);

  // only recognize events on descendants of a .active element
  $('#colors').on('click', '.active .liButton', colorHandler);
  $('#blog>ul').on('click', '.active>ul>li>h3', blogHandler);

  function colorHandler() {
      .css('backgroundColor', $.trim(this.innerHTML).toLowerCase());
  function blogHandler() {

  $('.liButtonBar .liButton:first').click();

In the sections below, the absence of the "active" class produces a grey background to indicate that the section is inactive.

The buttons above control which section is currently active.

The selector passed to the $.fn.on method takes advantage of the fact that the context for the selector is the document root, in order to determine if the clicked element is within an active section.

See my blog at

Try Out Some Colors

Blog Entries