It's better, when you have to append some new created content, to bind the events on the document, for a given selector, or for custom events.
For instance, if you are trying to bind a click on a given class '.your-class' :
$('.your-class').on('click', function (e) {
// ...
})
You would prefer to replace it by that :
$(document).on('click', '.your-class', function (e) {
// ...
})
It is exactly the same for jQuery UI:
You just would prefer to replace:
// Here you just bind a click on the existing elements of your class
this._on('.categoryNavigationExpandIcon', {
click: function(event) {
var $container = $(event.target).parent();
if( ($container).data('expanded') === false ) {
this._expand($container);
} else {
this._contract($container);
}
}
});
By:
// Bind a custom event on the document in order to delegate this event event to the new created classes
this._on(this.document, {
'click.categoryNavigationExpandIcon': function(event) {
var $container = $(event.target).parent();
if( ($container).data('expanded') === false ) {
this._expand($container);
} else {
this._contract($container);
}
}
});
You can find the updated the JSFiddle here: http://jsfiddle.net/vEAhq/7/
By the way, you can skip the closing tag when you create a element with jQuery !
$('<div>'); // instead of $('<div></div>');