Chained method calls doesn't work on original nor cloned element, why?

前端 未结 2 1801
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 19:01

I have the following HTML:

    
         


        
2条回答
  •  粉色の甜心
    2021-01-21 19:40

    Updated fiddle.

    I suggest to use a container then append the element you want to it, check the example below.

    Hope this helps.

    $(function() {
      var cond1 = $('#condition_value_1');
      var cloned_cond1 = cond1.clone();
      var cond1_select = '';
    
      $('#showme').click(function() {
        $("#my-container").html(cond1_select);
        $("#condition_value_1").select2({placeholder: 'Select choice',width:'100%'});
      });
    
      $('#clickme').click(function() {
        if ($('#condition_value_1').hasClass('select2-hidden-accessible')) {
          $("#condition_value_1").select2('destroy');
        }
        $("#my-container").html(cloned_cond1);
        $("#condition_value_1").show();
      });
    });
    
    
    
    
    

提交回复
热议问题