-1

I found different alternatives to toggle here for jQuery 1.9, but I don't get it to work im my case here:

$('.thumb.flip').toggle(
function () {
$(this).find('.thumb-wrapper').addClass('flipStop');
},
function () {
$(this).find('.thumb-wrapper').removeClass('flipStop flipIt');
}
);
  • if you want the same code work have a look at the migration project, else use an alternate like http://stackoverflow.com/questions/14382857/what-to-use-instead-of-toggle-in-jquery-1-8/14383246#14383246 – Arun P Johny Jan 22 '14 at 15:28
  • http://api.jquery.com/toggleClass Your code as-is seems to have a logic problem, or something's missing... What is the significance of `flipIt`? you never added it to begin with, so why would it be there anyway? – Kevin B Jan 22 '14 at 15:29

2 Answers2

0

You can use "click" event and then check using ":visible" (if the element is visible at the moment):

  • if the element is visible - hide it by adding a class like your code or just: ~.hide()

  • if the element isn't visible - add/remove class or use: ~.show()

Minister
  • 1,198
  • 2
  • 10
  • 18
0

You can give .flip a data-attribute

<div class="thumb flip" data-clicked="0">

$('.thumb.flip').click(function () {
    var data = $(this).data('clicked'), $descendant=$(this).find('.thumb-wrapper');
    if (data) {
        $descendant.removeClass('flipStop flipIt');
    } else {
        $descendant.addClass('flipStop');
    }
    data == 0 ? $(this).data('clicked', 1) : $(this).data('clicked', 0);
});

Or you can use elseif

$('.thumb.flip').click(function () {
    if ($(this).find('.thumb-wrapper').hasClass('flipstop')) {
        $(this).find('.thumb-wrapper').removeClass('flipStop flipIt');
    } else {
        $(this).find('.thumb-wrapper').addClass('flipStop');
    }
});
Anton
  • 32,245
  • 5
  • 44
  • 54