jquery-select2-4jquery-select2

Update select2 option text on-the-fly?


I want to change an option's text on the fly. The HTML can be changed easily by:

$('option[value=custom-pub]').text("New Text For Pub");

How can I force select2 to refresh the text? I don't want to destroy() and create the select2 object from scratch, because I want the user selection to stay selected.


Solution

  • Simply

    $("select").select2();
    

    works.