Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Remove event when clicked?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #25531
    Oskar
    Participant

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

    Code:
    $(‘div’).someEvent();

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

    #61283
    Chris Coyier
    Keymaster

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

    http://docs.jquery.com/Events/unbind

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

    #61182
    Hugo
    Member

    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)
  • The forum ‘JavaScript’ is closed to new topics and replies.