Get a free trial // Grow your CSS skills // Land your dream job

Remove event when clicked?

  • # July 22, 2009 at 5:26 am

    I’ve got an element with a function attached like this:


    When I click the div, I want the function to go away until I click the div again. How would I toggle the event?

    # July 22, 2009 at 1:38 pm

    You need to .unbind() it to remove it, and call it again to add it:

    You can unbind specific events, or call it with no params to unbind all of them.

    # July 23, 2009 at 4:25 pm

    Not sure what event you’re using, but it’s worth noticing the hover event is kind of special when using unbind()… In that very occasion you can’t just use $(‘#selector’).unbind(‘hover’), but you’ll have to unbind both the mouseover and the mouseout event…

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