Reputation: 199
I have a simple jQuery code that looks like this:
$( "#resp-navigation" ).one("click", function() {
$( "#navigation" ).slideToggle(500);
});
My HTML looks like this:
<div id="resp-navigation"> ... </div>
<nav id="navigation"> ... </nav>
My problem is that when I click on the #resp-navigation div, the #navigation keeps toggling. Does anyone meybe know why?
Thanks.
Upvotes: 2
Views: 1095
Reputation: 2300
If your intention is to have the '#navigation' div toggle each time someone clicks on the '#resp-navigation' div, then:
This: $( "#resp-navigation" ).one
Should be: $( "#resp-navigation" ).on
And then it works fine in this fiddle:
If, however, your intention is to only ever have the '#navigation' div toggle once (so it disappears and cannot be shown again), then your code does exactly that with no modifications, as you can see in this fiddle:
Upvotes: 3
Reputation: 784
Because you are using .one(*). Using like $(".btn1").click(function(){...}
will work for multiply click.
Upvotes: 0
Reputation: 618
As @trevor said, it should be on('click'), not one('click').
If you are seeing it ping ponging my guess is you have another on-click listener assigned elsewhere in the code that is doing the same thing.
Upvotes: 0