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() {

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

$('.btn-list').click(function() {

it does!

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

$('.btn-list').toggle(function() {
}, function() {

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

2 Years
Discussion Span
Last Post by gentlemedia

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.


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.