Reputation: 4253
I have this jquery function to load a page based on a href
link:
<script type="text/javascript">
$(document).ready(function(){
$("#test a").click(function( e ){
e.preventDefault();
var href = $( this ).attr('href');
$("#content").load( href , function(){
$('#content').hide().fadeIn(500);
});
});
});
</script>
My question is, how to show loading div while the href page is loading?
<div id=loading>LOADING...</div>
thank you friends!
Upvotes: 1
Views: 659
Reputation: 3362
Do the loading
div hidden by default:
#loading{
display: none;
}
Then, show it BEFORE you call load
and hide it in the callback function.
....
var href = $( this ).attr('href');
$("#loading").show();
$("#content").load( href , function(){
$("#loading").hide();
....
Upvotes: 1
Reputation: 374
You may do like this way:
<script type="text/javascript">
$(document).ready(function(){
$("#test a").click(function( e ){
e.preventDefault();
$("#loading").html("Loading");
var href = $( this ).attr('href');
$("#content").load( href , function(){
$('#content').hide().fadeIn(500);
});
$("#loading").html("");
});
});
</script>
Upvotes: 1