View Full Version : MooTools: Chaining Events

08-14-2010, 11:23 PM
I wrote a small script to "Add to favorites" with AJAX & MooTools and came up with the following:

function addFavorite(id) {
url = '/includes/add_favorite.php?r='+id;
new Request({
url: url,
method: 'get',
onSuccess: function(responseText) {
var myFx = new Fx.Tween('favorite');
myFx.start('opacity', 0).chain(function(){
$('favorite').set('html', '<a><img src="/images/heart.png" width=24 alt="save"> saved!</a>');
this.set('opacity', 1);

Which fades the element out, replaces the text and link, then fades it back in.

Is there a better way to write this without having to call the callChain() method? I want to be sure I'm properly chaining methods.