In this stackoverflow post the accepted answer claimed that it is possible to use toggleClass
with a delay. But i did not find any information about a delay parameter on the official jquery API website.
I tried it but there is no delay after a click on the div.
$("div#test").click(function() {
$(this).toggleClass('light', 2000).toggleClass('dark', 2000);
});
div {
border: 1px dashed black;
}
.light {
background-color: white;
}
.dark
{
background-color: black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="light" id="test">
<p style="color:red">click here</p>
</div>