Grux
Grux

Reputation: 584

jQuery: click indicator on div

It may be obvious I'm very new to web development. Anyway, I'm trying to create a click event on a div and change its background color. But I want the background to change back to its original color after the click up. Here is what I have:

jQuery:

$('.details1').click(function() {
    $(this).toggleClass('on').delay(200).toggleClass('on');
});

css:

div.on {
    background: #F78181;
}

I don't exactly want a millisecond delay, that's just for debugging. Just want to change background on click down and up. Thanks.

Upvotes: 1

Views: 305

Answers (1)

VSri58
VSri58

Reputation: 3761

You have to use setTimeout() function for your problem instead of delay()

$('.details1').click(function(){
        setTimeout(function(){ $('#clrd').toggleClass('on'); }, 200);
    });

you can change the time (milliseconds) as per your need. In this case it is 200ms

Check this Fiddle

Upvotes: 2

Related Questions