Say a element has value 55:
<span id="some">55</span>
I want to:
So I tried:
$("#some").fadeOut("slow").html("44").fadeIn("slow");
But the above first sets the span's content to 44, and then fades out and fades in.
So I tried with a callback:
function fadeOutComplete(){
$("#some").html("<%= @cc %>").fadeIn("slow");
}
$("#some").fadeOut("slow",fadeOutComplete);
Now this works, but it's looks and feels clunky. Is there some way to write this DRYer and more jQuery-er? (not even sure what I mean by jQuery-er!)
How could I pass in the element whose value is to be set and the value to be set to fadeOutComplete
so I can make that callback sort-of generic?
Check this...
$("#some").fadeOut("slow", function() {
$(this).html("<%= @cc %>").fadeIn("slow");
});
fadeOut()
, this
is pointing to the native DOM element. This allows you to reference it again in a DRY way.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With