Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Selectable: Bind to first-generation children only

I have a group of elements which I want to be selectable.

jQuery UI Selectable seems to be the right tool, but I run into problems where the functionality seems to be bound to all of the child elements, with all the classes being applied.

I want to ensure that the classes and binding of events is only applied to the first generation of children, and not their nested elements.

Here's a jsFiddle which should help illustrate what I'm trying to prevent: http://jsfiddle.net/ncKEW/

The Code HTML

<div id="group">
    <div class="unit">
        <h2>Title</h2>
        <div class="content">
            Dulce et decorum
        </div>
    </div>
    <div class="unit">
        <h2>Title</h2>
        <div class="content">
            Dulce et decorum
        </div>
    </div>
    <div class="unit">
        <h2>Title</h2>
        <div class="content">
            Dulce et decorum
        </div>
    </div>
    <div class="unit">
        <h2>Title</h2>
        <div class="content">
            Dulce et decorum
        </div>
    </div> </div>

js

$(document).ready(function(){
    $('#group').selectable();
});

Css (just for illustration)

#group{padding: 12px;}
h2{font-size: 1.2em;margin: 2px 0;}
.unit{background: blue;}
.ui-selected{background: yellow;}
like image 884
daveyfaherty Avatar asked Apr 26 '13 10:04

daveyfaherty


1 Answers

use the filter option.

$(document).ready(function(){
    $('#group').selectable({
        filter: " > div"
    });
});

Demo: Fiddle

like image 95
Arun P Johny Avatar answered Nov 09 '22 23:11

Arun P Johny