0

I'm trying by clicking on a button to toggle a class on a parent element which is 5 levels higher, so I though that this would do the trick:

$('.btn-list').click(function() {
    $(this).parents('.mix-serie').toggleClass('animate')
});

But unfortunately it didn't, but if I just add a class,

$('.btn-list').click(function() {
    $(this).parents('.mix-serie').addClass('animate')
});

it does!

Then I thought doing it with .toggle() instead of .click()like this:

$('.btn-list').toggle(function() {
    $(this).parents('.mix-serie').addClass('animate')
}, function() {
    $(this).parents('.mix-serie').removeClass('animate')
});

But again no luck! So what's going on?

I'm on Google on the Mac and I have no errors in the console re this (there's 1, but is related to something else and is IE specific).

Edited by gentlemedia

1
Contributor
2
Replies
10
Views
2 Years
Discussion Span
Last Post by gentlemedia
0

I replicated the situaion in a pen and there it toggles the class on the parent, so there's a conflict with something else on my page.

0

I took the function out of the document ready function and now it toggles the class properly.

Kudos to myself... do I also get rewarded by solving my own questions? :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.