STP38
STP38

Reputation: 331

jQuery getting id of the element which is sortable

I got some div's which are sortable etc.. But they got all the same classes, so if I drag one, all the contents of the div's are hiding. I want to get 'id' of the div i'm dragging, and put it into hide and show function.

It should be like this..

jQuery code:

$("#column-right").sortable({
    connectWith: ".sort",
    handle: ".title",
    placeholder: "salih",
    cursor: 'move',
    revert: 'invalid',
    start: function() {
        .click(function() {      // I know it is wrong but it should be like this
        var id = $(this).attr('id')
        }
        $('id').hide();
    },
    stop: function() {
        .click(function() {   // same
        var id = $(this).attr('id')
        }
        $('id').show();
    }
});

EDIT: Example my problem: fiddle

Upvotes: 0

Views: 117

Answers (1)

Pavlo
Pavlo

Reputation: 711

Please let me know if this is something you were looking for:
JavaScript Code

$("#column-left, #column-middle, #column-right").sortable({
    connectWith: ".sort",
    handle: ".title",
    placeholder: "salih",
    cursor: 'move',
    revert: 'invalid',
    start: function() {
        $(this).find('.contents').hide();
    },
    stop: function() {
        $(this).find('.contents').show();
    }
});
$(".sort").disableSelection();

In general, $(this).find('.contents') will be exactly the child element (content) which you are dragging.

Also, I have merged your 3 identical methods into 1 avoiding duplicates and any mess in the code.

Upvotes: 1

Related Questions