0

Hi I use jquery call back function to removeClass, Now I want to attach delay with this function. My function is

$(function(){
$('a').click(function(){
$('.mydiv').find('.div1').addClass('jmnew').show('slow', function(){
$('.mydiv').find('.jmnew').removeClass('jmnew');
});
});
});

HTML//

<div class="mydiv">
<div class="div1" style="display:none">
abc
</div>
<a href="#">click me</a>
</div>

fiddle link

2 Answers 2

2

You should use setTimeout

$(function(){
    $('a').click(function(){
        $('.mydiv').find('.div1').addClass('jmnew').show('slow', function(){
            setTimeout(function() {
                $('.mydiv').find('.div1').removeClass('jmnew')
            },2000);
        });
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

You will need to use setTimeout function, since jQuery's delay() only works with queued effects.

$(function() {

    $('a').click(function() {
        $('.mydiv').find('.div1').addClass('jmnew').show('slow', function() {

            setTimeout(function() {
                $('.mydiv').find('.jmnew').removeClass('jmnew')
            }, 1000);
        })
    })
})​

See the DEMO.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.