How to disable function on click event?

can

I have a button which toggle 2 divs. And a function which do the same thing after 5 seconds. But when the user click on the button, the function also works. How can I disable the function when the button is clicked?

This is what I want: If click on .turn-button, disable function show_back.

My code:

 $(document).ready(function() {

    // Toggle
    $(".toggle-class").hide();

    $(".turn-button").click(function() {
        $(".toggle-class").slideToggle(500);
        $(".toggle-class-back").slideToggle(500);
    }); 

    // Show back after 7 seconds
    $(function(){
       function show_back(){
            $(".toggle-class").slideToggle(500);
            $(".toggle-class-back").slideToggle(500);
       };
       window.setTimeout( show_back, 5000 ); // 5 seconds
    });

});
arul prince

you can use .off() function to disable click event

$("p").on("click", function() {
  $(this).css("background-color", "red");
  $("#clicked").html("clicked");
});
$("button").click(function() {
  $("p").off("click");
  $("#clicked").html("disabled");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>

<head>
</head>

<body>
  <p> Test Data</p>
  <div id="clicked"></div>

  <button>Click</button>
</body>

</html>
Click this paragraph to change its background color and changed div text to clicked.

Click the button below and then click on this paragraph (the click event is removed).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to disable marker click event?

From Dev

How to disable click event on JQuery tabs?

From Dev

How to disable jQuery click event on label?

From Dev

How to disable click event on leaflet map only?

From Dev

How to disable the dojo button with click event

From Dev

How to disable click event on JQuery tabs?

From Dev

How to disable the click event for the customized checkbox

From Dev

How to disable the click event in electron app

From Dev

How to disable default PowerPoint event functionality of double click and right click?

From Dev

jquery how to disable an scroll event on click of another event

From Dev

JQuery: Disable click event

From Dev

JQuery: Disable click event

From Dev

How to disable the click if a function is in active status

From Dev

how to disable datagridview mouse click event for headers in c#

From Dev

How to disable click event on rowChart in dc.js

From Dev

How to disable click event in slideshow until animation is finished and then bind it again?

From Dev

how to disable ng-click event in confirmation Popup Button

From Dev

how to disable ng-click event in confirmation Popup Button

From Dev

How can I disable the ng-click event for a span?

From Dev

How to call a function outside of javascript click event

From Dev

How to attach click event function in Highcharts

From Dev

Disable a function on click

From Dev

jquery click disable the function

From Dev

How do i use a click function to undo a click event?

From Dev

How do i use a click function to undo a click event?

From Dev

How do you disable click events from the contextmenu event when using Ctrl+Click in Safari for Mac?

From Dev

How to disable click on dates

From Dev

How to disable click button?

From Dev

How to disable event temporarily

Related Related

  1. 1

    How to disable marker click event?

  2. 2

    How to disable click event on JQuery tabs?

  3. 3

    How to disable jQuery click event on label?

  4. 4

    How to disable click event on leaflet map only?

  5. 5

    How to disable the dojo button with click event

  6. 6

    How to disable click event on JQuery tabs?

  7. 7

    How to disable the click event for the customized checkbox

  8. 8

    How to disable the click event in electron app

  9. 9

    How to disable default PowerPoint event functionality of double click and right click?

  10. 10

    jquery how to disable an scroll event on click of another event

  11. 11

    JQuery: Disable click event

  12. 12

    JQuery: Disable click event

  13. 13

    How to disable the click if a function is in active status

  14. 14

    how to disable datagridview mouse click event for headers in c#

  15. 15

    How to disable click event on rowChart in dc.js

  16. 16

    How to disable click event in slideshow until animation is finished and then bind it again?

  17. 17

    how to disable ng-click event in confirmation Popup Button

  18. 18

    how to disable ng-click event in confirmation Popup Button

  19. 19

    How can I disable the ng-click event for a span?

  20. 20

    How to call a function outside of javascript click event

  21. 21

    How to attach click event function in Highcharts

  22. 22

    Disable a function on click

  23. 23

    jquery click disable the function

  24. 24

    How do i use a click function to undo a click event?

  25. 25

    How do i use a click function to undo a click event?

  26. 26

    How do you disable click events from the contextmenu event when using Ctrl+Click in Safari for Mac?

  27. 27

    How to disable click on dates

  28. 28

    How to disable click button?

  29. 29

    How to disable event temporarily

HotTag

Archive