Affecting only one element with jQuery toggle

时间:2015-10-30 22:46:36

标签: javascript jquery jquery-ui

So I have got this code

$('.item').click(function () {
    if ($(".secondary", this).is(":hidden")) {
        $(".primary", this).toggle('slide', {
            direction: 'right'
        }, 500, function () {
            $('.secondary', this).toggle('slide', {
                direction: 'left'
            }, 500);
        });

    }
});

Current behavior is that when I click .item, .primary slides to the right, but .secondary doesn't slide in at all.

Fiddle: http://jsfiddle.net/zm3zp6ax/

1 个答案:

答案 0 :(得分:3)

$('.item').click(function () {
    var $this = $(this);
    if ($(".secondary", this).is(":hidden")) {
        $(".primary", $this).toggle('slide', {
            direction: 'right'
        }, 500, function () {
            $('.secondary', $this).toggle('slide', {
                direction: 'left'
            }, 500);
        });

    }
});

DEMO