سؤال

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?

هل كانت مفيدة؟

المحلول

I guess that is what you need.

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

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

نصائح أخرى

Try this:

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

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top