Question

I'm trying to select every div with class='selectthis' and return their sibling divs (also make them un-draggable) if parent div's data-id not equals to 0.

Here is fiddle: http://jsfiddle.net/umvQJ/1/

Here is my code:

<div class="selectthis" data-id="0">
     <div class='draggable'>don't return this</div>
</div>

<div class="selectthis" data-id="1">
     <div class='draggable'>return this</div>
</div>

<div class="selectthis" data-id="2">
     <div class='draggable'>return this</div>
</div>
$(document).ready(function() {
    $('.draggable').draggable();

    $(".selectthis").filter(function () { 
        return $(this[data-id!=="0"]).siblings(div); 
    }).draggable({revert: 'invalid'});
});

Where am I doing wrong?

Was it helpful?

Solution

I guess that is what you need.

$(document).ready(function () {
    $(".selectthis").not('[data-id="0"]').find('.draggable').draggable();
});

http://jsfiddle.net/umvQJ/2/

OTHER TIPS

Try this:

$(document).ready(function () {
    $(".selectthis").filter(function () {
        return $(this).data('id') == 0
    }).siblings('div').draggable({
        revert: 'invalid'
    });
});

Demo: http://jsfiddle.net/umvQJ/3/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top