I have this code:
$(document).ready(function(){
$(".links a").click(function(e){
var toLoad = "products.html #" + this.id;
$('#block').fadeTo('fast',0,loadContent);
function loadContent() {
$('#block').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#block').fadeTo('slow',100);
}
e.preventDefault();
});
});
The idea is:
- click on a link to trigger (check!)
- the “block” div fades to 0 (check!)
- the content is switched out (check!)
- the “block” div fades back 100 (whoops!)
The behavior I see is that the div fades out, then pops back with new content as soon as the fadeOut is completed.
Any thoughts on this?
Change this:
to
To explain: you’re calling the function immediately (and passing its non-existent return as to
load()) whereas you want to pass the function (rather than what it returns) as the callback.Note: also,
fadeTo()states:so you should probably change:
to