I\'m looking for a way to attach a click-event to a select2-result-item. I\'ve gone ahead and formatted both result and selection via
function format(state)
the thing seems to be that the tgas will be deleted right after the box is closed. Therefore the click event cannot be fired.
I've changed a few things + the event that will be listened on. It's now a mousedown...
function format(state) {
if (!state.id) return state.text; // optgroup
return state.text + " link";
}
$("select").select2({
formatResult: format,
formatSelection: format,
escapeMarkup: function(m) { return m; }
}).on('select2-open',function(){
console.log($('.info'))
$('.info').on('mousedown', function(event){
console.log("click")
$('#log').text( "clicked" );
event.preventDefault();
});
});