2

Having the following:

$('#navMain .nav1').hover(function () {
    $(this).addClass('hover');
    if ($.browser.msie && $.browser.version < 7) 
        $('select').css('visibility', 'hidden');
}, function () {
    $(this).removeClass('hover');
    if ($.browser.msie && $.browser.version < 7) 
        $('select').css('visibility', 'visible');
});

I need to delay the executing of addClass('hover') after hovering over $('#navMain .nav1') element.

I've tried this but it doesn't work:

$(this).delay().addClass('hover');
if ($.browser.msie && $.browser.version < 7) 
    $('select').delay().css('visibility', 'hidden');

thanks

2 Answers 2

9
setTimeout( function(){

  // your stuff here

}, 500); // delay 500 ms

with your code:

$('#navMain .nav1').hover(

  function () {
    setTimeout( function(){
        $(this).addClass('hover');
        if ($.browser.msie && $.browser.version < 7) $('select').css('visibility', 'hidden');
    }, 500); // delay 500 ms
  }, 

  function () {
    $(this).removeClass('hover');
    if ($.browser.msie && $.browser.version < 7) $('select').css('visibility', 'visible');
  }

);
Sign up to request clarification or add additional context in comments.

Comments

3

If a simple javascript delay can help you, you can do as follow:

setTimeout(function() {
  // your code here
}, 3000);

With the following signature: setTimout(functionToExecute, delayInMs);

and the documentation: http://www.w3schools.com/js/js_timing.asp

Hopping I help you.

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.