jQuery UI Selectable Without Selection Box

profile for Nikola at Stack Overflow, Q&A for professional and enthusiast programmers
I'm a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%). In this category (stackoverflow) of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread here.

My question was:

Given this example here: http://jqueryui.com/selectable/#display-grid I would like to make a selection without the "selection box" that appears when you click 'n drag. Namely, when I click on number 5 and drag to number 6 and then to 10 I get this:

enter image description here

where in fact what i would like to is drag from 5 to 6 to 10 and have only them selected without 9.

I searched the docs and couldn't find that option, and my google skills didn't bring me any luck, and I thought this must have been already done it's just so happens I can't grasp it on my own or find an existing solution, so any help here is appreciated (not saying you should do the research for me, am just hoping someone dealt with this before so he can point me to the right direction).

It also could be I'm missing the point in trying to accomplish this with jquery UI but this was the first such example I found that fits (kind of) what I want to accomplish.

 The rather extensive answer, by Dom, was:

First, you might want to hide .ui-selectable-helper or change the CSS:


Next, do something like this:

$(function(){var _mousedown =false;
        selecting:function(event,ui){if($('.ui-selecting').length ==1)



DEMO: http://jsfiddle.net/dirtyd77/7UVNS/5/ (HELPER HIDDEN)

http://jsfiddle.net/dirtyd77/7UVNS/6/ (HELPER VISIBLE)

Let me know if you have any questions!


.selectable() is not able to do what you are looking for. However, here is something I created. Hope it helps!


$(function(){var _mousedown =false,
    $('#selectable li').mousedown(function(){
        _mousedown =true;
        $('#selectable li').attr('unselectable','on').css('user-select','none');
        $('#selectable li').removeAttr('unselectable style');}).mouseenter(function(){if(_mousedown){if($(this).hasClass('ui-selecting'))

            _last =  $(this)[0];

DEMO: http://jsfiddle.net/dirtyd77/7UVNS/9/

***UPDATE #2:***

If you want to use this on a mobile device, I recommend changing up the format entirely to avoid any possible pitfalls. Here is how I would go about it:


$(function(){var _clicked =false;
        _clicked =false;
        $('#selectable li').removeAttr('unselectable style');
    $('#selectable li').click(function(){if(!_clicked){
            _clicked =true;
            $('#selectable li').attr('unselectable','on').css('user-select','none');

*NOTE: you might want a $('body').click() to act as the end_selection button.

DEMO: http://jsfiddle.net/dirtyd77/7UVNS/13/

Written by Nikola Brežnjak