The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Remove class for the link, when the div is closed

  • # March 13, 2013 at 7:53 am

    Hi, I was integrating a jquery content box which toggles on click of the navigations. I am adding a class=’select’ to the respecting navigation,which is clicked and the div is open, but i am not able to remove the class when I click again on it and the div is closed.

    here is the code,

    Can anybody help me out ? Thanks in Advance

    # March 13, 2013 at 3:27 pm

    This reply has been reported for inappropriate content.

    Something like this, perhaps:

    Just added the select class in the animate complete callback.

    Edit: This was done in a bit of a hurry, as I had a moment between meetings . . . there’s a lag in updating the select class that could probably be fixed by using another method.

    The reason it wasn’t working for you was the delay in the animation. The animation hadn’t had time to finish before you checked if the div was hidden, so that always returned false.

    Another way around it would be to put a delay before the check using setTimeout, like so:

    Note that the delay in setTimeout must be longer than the duration of the animation. Since your animation is set to the default duration of 400, I set my setTimeout to 420 to compensate.

    # March 15, 2013 at 11:06 am

    no need for timeouts or delays,

    all i did here was reorder your jQuery a little bit. works fine now.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed