Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-14-2012, 07:50 PM   PM User | #1
The Noob Coder
New Coder

 
Join Date: Jul 2012
Posts: 72
Thanks: 1
Thanked 0 Times in 0 Posts
The Noob Coder is an unknown quantity at this point
Question How do I get a callback function to only call once?

I have a callback function given with a toggle function. The idea is that all the <div> elements will be toggled and I will get one alert message. Now I know I can easily solve this problem with some sort of flag variable (like a boolean to see if this was the first call or not), but I don't want to do it like that if there is a better way.

Here's the jQuery:
Code:
$(':submit').click( function() {
    $('div').toggle(slow, function() {
           alert("The divs were all toggled!");
     });
});
What happens is that I get an alert (one after another) for each <div> element that was toggled (because the toggle function is called on each <div>, and therefore, the call back's alert is called on each <div>). Is there a way to get to call the alert() only once, without using some sort of flag variable?
The Noob Coder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:42 AM.


Advertisement
Log in to turn off these ads.