[Solved] why animate() doesn’t work well with data()?


My guess is that you should be using $(this).data(), not $('div').data(), so that each DIV will keep track of its own animation state.

    $('div').click(function () {

        var data =  $(this).data('animate');


        if ( data == 10  ) {
            $(this).animate({ height: 100 }, 200);
            $(this).data("animate","100");

            }

        else if ( data == 100 ) {
            $(this).animate({ height: 10 }, 200);
            $(this).data("animate","10");

            }

            console.log(data);

    });

0

solved why animate() doesn’t work well with data()?