jquery - deselect tag with 'select2' -


hi new java script.

i try save in array selected tags, work ok, when press 'x' on tag want delete array, how can this?

 $( "#select2-2" ).change(function() {      $( "#select2-2 option:selected" ).each(function() {          strarr[i] = $( ).text();          i++;      });  }).trigger("change"); 

my html code:

<select id="select2-2" class="form-control" multiple>    <option>tag1</option>    <option>tag2</option>    <option>tag3</option>    <option>tag4</option>    <option>tag5</option> </select> 

more explain select-2:

https://select2.github.io/

select-2 create tags when select option select list, this:

[tag3 x][tag2 x][tag4 x]

when select option select list, visual tag.. save tags in array. when press 'x' want remove tag array.

any idea how can this?

add remove button, link bit of code: $('#select2-2').find(':selected').remove(); remove selected options within select2-2

var strarr = [];    $("#select2-2").change(function () {       var = 0;       $("#select2-2 option:selected").each(function () {           strarr[i] = $(this).text();           i++;       });   }).trigger("change");    $('#remove').click(function(){      $('#select2-2').find(':selected').remove();  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <select id="select2-2" class="form-control" multiple>     <option>tag 1</option>     <option>tag 2</option>     <option>tag 3</option>     <option>tag 4</option>     <option>tag 5</option>  </select><br>  <button id="remove" type="button">remove</button>


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -