1

I got a button to click to show a map(slideDown). After showing, if the user click again the button, the map will hide(slideUp). I don't know how to remove the click event in the function, cause i want to detect the second click. This is my function code now:

function subangMap() {
    $("#mapInfo").unbind();
    $("#info").css("height", "760px");
    $("#mapInfo").text("Click here to hide map");
    $("#subangMapSlide").slideDown();


    $("mapInfo").click($("#subangMapSlide").slideUp());
}

This is my edit code with off(). But still not working..

function subangMap()
    {
    $("mapInfo").off('click');
    $("#info").css("height","760px");
    $("#mapInfo").text("Click here to hide map");
    $("#subangMapSlide").slideDown();

     $("mapInfo").click($("#subangMapSlide").slideUp());
    }
veeyikpong
  • 690
  • 7
  • 19
  • `unbind()` has been deprecated, you should look at `off()` – Mister Epic Nov 18 '13 at 15:15
  • http://stackoverflow.com/questions/825112/how-to-remove-all-click-event-handlers-in-jquery http://stackoverflow.com/questions/209029/best-way-to-remove-an-event-handler-in-jquery – Andre Figueiredo Nov 18 '13 at 15:15
  • @ChrisHardie `unbind()` is not deprecated but that's true, `off()` is preferred method – A. Wolff Nov 18 '13 at 15:16
  • Ah, my bad, they're not deprecated, but they're not the preferred choice. From the jQuery site: "As of jQuery 1.7, the .on() and .off() methods are preferred to attach and remove event handlers on elements" – Mister Epic Nov 18 '13 at 15:18
  • Read [jQuery bind/unbind and on/off](http://blog.mostlystatic.com/2012/07/whats-relationship-between-jquery.html) – Tushar Gupta - curioustushar Nov 18 '13 at 15:21

1 Answers1

2

You need .slideToggle()

$("#mapInfo").click(function () {
    $("#subangMapSlide").slideToggle();
});
Tushar Gupta - curioustushar
  • 54,013
  • 22
  • 95
  • 103