I have the following jQuery code. What I am trying to do is perform an if statement to see if $(“#div3”).slideToggle(“slow”); exists – and if so, to not execute it. Basically, the code a level up from this is run various times during a page view. So if #button is clicked, after the parent “click function” is click more than once, #div3 will toggle many times. I have found other work arounds such as unbinding the element. However, i can’t do that or other workarounds for various reasons, as it will affect my other code. There are many more methods going on than this single one within the code I showed. Is there a way to check if $(“#div3”).slideToggle(“slow”); already is existing in the current page? Thanks!
$('#button').click(function() {
$("#div3").slideToggle("slow");
});
You can check if a function exists by using this:
Especially you can check if an event is bound with:
Alternatively you can just add a new property to $(‘#div3’) like so: