jqueryjquery-uijquery-ui-selectable

jQuery UI selectable isnt displaying the selection outline, why?


On the jQuery UI selectable demo page: http://jqueryui.com/demos/selectable/#default when you select elements, you can see the selection box outline. How come this doesnt appear when I try it?

This isnt my fiddle, but it also has the same problem: http://jsfiddle.net/jMDVm/40/


Solution

  • It's because it's missing the jQuery UI stylesheet, which contains the class for styling the selection helper box. Add the following to your CSS:

    .ui-selectable-helper {
      position: absolute; 
      z-index: 100; 
      border: 1px dotted black; 
    }
    

    $(document).ready(function() {
      $("#selectable").selectable({
        selected: function(event, ui) {
          $('.status').text("Selected");
        },
        selecting: function(event, ui) {
          $('.status').text("Selecting");
        }
      });
    });
    #wrapper {
      width: 250px;
      height: 100px;
    }
    
    #selectable {
      background: black;
      width: 250px;
      height: 16px;
    }
    
    #selectable .ui-selecting {
      background: silver;
    }
    
    #selectable .ui-selected {
      background: gray;
    }
    
    #selectable div {
      background-color: #777;
    }
    
    .ui-selectable-helper {
      position: absolute;
      z-index: 100;
      border: 1px dotted black;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js"></script>
    <div id="wrapper">
      <div id="selectable">
        <div>Hello</div>
        <div>Select</div>
        <div>Me</div>
      </div>
    </div>
    <div class="status"></div>