Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Created December 16, 2020 16:00
Show Gist options
  • Save bhaireshm/60c8b3aeeac1081a9c2f72f8be97872b to your computer and use it in GitHub Desktop.
Save bhaireshm/60c8b3aeeac1081a9c2f72f8be97872b to your computer and use it in GitHub Desktop.
Add button to select2 dropdown
/**
* @param className - class name of the select tag (you can change to id)
* @param text - content for the link
*/
function addBtnToDropdown(className, text) {
var flg = 0;
$(`.${className}`).on("select2:open", function () {
flg++;
if (flg == 1) {
let $this_html = `<hr style="margin:2px"><a href="javascript:void(0)"
onclick="javascript:$('.${className}').select2('close');">${text}</a>`;
$(".select2-results").append(`<div class='select2-results__option text-center'>${$this_html}</div>`);
}
});
}
@adil62
Copy link

adil62 commented Aug 9, 2021

thanks

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