Bug Tracker

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#1067 closed bug (fixed)

fade callback triggered once for every element faded

Reported by: tabacco Owned by:
Priority: minor Milestone: 1.1.3
Component: effects Version: 1.1.2
Keywords: Cc:
Blocked by: Blocking:

Description

I'm not 100% certain this is a bug (as opposed to by design), but just in case...

It looks like calling one of the fade functions (fadeOut/fadeIn/fadeTo) on a selector that matches multiple objects in the code will cause the callback function to be fired once per object matched, instead of once.

For example...

<script type="text/javascript">
$(document).ready(function() {
     $(".some_class").fadeOut("normal", function() { 
          alert("hey!");
     });
}
</script>
<table>
<tr>
<td class="some_class">...</td>
<td class="some_class">...</td>
<td class="some_class">...</td>
</tr>
</table>

This will cause three "Hey!" alerts to happen. This becomes problematic when you want to fade out several divs (or whatever), populate them from an ajax request, and then fade them back in. Having the ajax request inside the callback means that three requests get made. this

Change History (3)

comment:1 Changed 16 years ago by joern

There are other cases where you need the callback for each element. The situation you describe could be solved by fading out a parent element, replacing its content via AJAX an fading it back in.

comment:2 Changed 16 years ago by tabacco

Nevertheless, at the very minimum this behavior should be documented.

comment:3 Changed 16 years ago by john

Resolution: fixed
Status: newclosed

I've updated the documentation to clarify this point: http://docs.jquery.com/Effects

Note: See TracTickets for help on using tickets.