Skip to content

Instantly share code, notes, and snippets.

@Strae
Created July 25, 2014 08:34
Show Gist options
  • Save Strae/e055f7285f5fd6b7c069 to your computer and use it in GitHub Desktop.
Save Strae/e055f7285f5fd6b7c069 to your computer and use it in GitHub Desktop.
Adding custom htlm elements to chosen
// chosen.jquery.js, function Chosen.prototype.set_up_html, add this in row 582
if('undefined' !== this.options.afterContent){
var afterContent = jQuery(document.createElement('div'))
.addClass('chosen-after-content')
.html(this.options.afterContent);
this.container.find('ul.chosen-results').after(afterContent);
}
// then add your custom html like
jQuery("#foo").chosen({
afterContent: '<span id="button" class="btn btn-primary icon-ok btn-xs">Click me</span>'
});
@koenpunt
Copy link

Why not simply do this on the chosen:ready event?

$('#foo').on('chosen:ready', function(event, data){
    $(data.chosen)
       .find('ul.chosen-results')
       .after('<span id="button" class="btn btn-primary icon-ok btn-xs">Click me</span>');
}).chosen();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment