The basic syntax for delaying a function using setTimeout is this: setTimeout(function() { // ...code here executes when the timeout is complete }, 2000 /* Length of timeout, in milliseconds */);
so for your example, something like this should work: $(document).ready(function(){ $("#barcode span").hover( function () { $(this).addClass("barover"); }, function () { setTimeout(function() { $(this).removeClass("barover"); }, 2000); } ); }); On Aug 30, 9:49 am, a1anm <alanmoor...@gmail.com> wrote: > Hi, > > I have this code: > > $(document).ready(function(){ > > $("#barcode span").hover( > function () { > $(this).addClass("barover"); > }, > function () { > $(this).removeClass("barover"); > } > ); > }); > > I would like to add a timeout so that the removeClass gets delayed for > a specified amount of time. Any ideas how to add a settimeout to > this? > > Thanks!