Reputation: 101
I want to run a piece of code after first completing jquery hide
function but the code run before waiting to completely hide the elements.
This is the code:
$('p').hide(1000);
$('.menu-link').each(function(n, e){
var len = $(e).next('ul').find('a').length;
$(e).find('div').text(len);
});
How can I run this code after completing hide()
function that is complete in 1000 ms?
Upvotes: 0
Views: 53
Reputation: 988
use this code:
setTimeout(function(){ }, 1500);
or use callback!!
$('element').hide("1000", function() { ... });
Upvotes: 0
Reputation: 23816
Use Call back to hide event
$('p').hide(1000, function () {
$('.menu-link').each(function (n, e) {
var len = $(e).next('ul').find('a').length;
$(e).find('div').text(len);
});
});
Upvotes: 3
Reputation: 160833
Write as callback:
$('p').hide(1000, function() {
$('.menu-link').each(function(n, e){
var len = $(e).next('ul').find('a').length;
$(e).find('div').text(len);
});
});
Upvotes: 0