Search code examples
javascriptjqueryhtmlcsstoggleclass

ToggleClass not adding Jquery Delay?


I am trying to add a delay to the toggleclass 'slidein' however it doesn't seem to be adding to it.

here is my fiddle

and here is my code;

 $(function () {
        $(".expand").on("click", function () {
            $(this).next().slideToggle();

                if ($(this).next().css("display", "block")) {



                    $(this).next().children('#slidinghold').delay(5000).toggleClass('slidein');


            }

            $expand = $(this).find(">:first-child");


            if ($expand.text() == "\u25B6") {
                $expand.text("\u25BC");


            } else {
                $expand.text("\u25B6");
            }
        });

    });

Solution

  • Try this:

    $(this).next().children('#slidinghold').delay(5000).queue(function(){
        $(this).toggleClass("slidein").dequeue();
    });
    

    Fiddle