The task is this: when selecting from select, select values should turn into a label with text from select and next to the "Edit" button. If you click on the "Change" label and the button again turns into a select. The first transformation works, but the button does not. What am I doing wrong?
HTML:
<select id="select_customer" data-placeholder="Покупатель" tabindex="2"> <option value=""></option> <option value="United States">United States</option> <option value="United Kingdom">United Kingdom</option> <option value="Afghanistan">Afghanistan</option> </select>
Js:
$("#select_customer").change(function (){ var sp = $("#select_customer :selected").text(); var $span = $('<h3><span class="label label-primary">' + sp +'</span><button id="choose_customer" type="button" class="btn btn-default"> Изменить</button></h3>') $("#select_customer").select2('destroy').replaceWith($span); }); $("#choose_customer").click(function(){ $span.replaceWith($("#select_customer").select2()); })
;