Can I put delay(500) before an addClass()?
Asked Answered
G

2

25
$(document).ready(function(){
    $("#info-text-container").click(function(){
        $("#info-text").delay(500).addClass("info-text-active");
    });   
});

This does not put an delay on it when it gets clicked. Which I want to accomplish. Why and is this hackable, possible to overcome? Thanks!

Gismo answered 16/3, 2013 at 10:49 Comment(0)
R
46

delay only works with animating methods, you can use setTimeout function:

$("#info-text-container").click(function(){
    setTimeout(function(){
       $("#info-text").addClass("info-text-active");
   }, 500);
});
Rhnegative answered 16/3, 2013 at 10:52 Comment(0)
H
41

Not quite like that, but like this for example:

$("#info-text").delay(500).queue(function(next) {
  $(this).addClass("info-text-active");
  next();
});
Hairsplitter answered 16/3, 2013 at 10:52 Comment(1)
Thanks, but The answer above was a little bit better to me. You got a up arrow though ;)Gismo

© 2022 - 2024 — McMap. All rights reserved.