So, it's just a simple issue with scope. Try this instead (which was
working when applied via FireBug to your demo page:

$(document).ready(function(){
    $("#barcode span").hover(
      function () {
                $(this).addClass("barover");
      },
      function () {
           // Store span reference
          var span = $(this);
           setTimeout(function() {
                span.removeClass("barover");
          }, 2000);
      }
    );
  });

Note that the timer used here is 2000 milliseconds (2 seconds), so
you'll likely have to tweak that value to fit your needs. Hope that
helps.
On Aug 30, 7:22 pm, a1anm <alanmoor...@gmail.com> wrote:
> Hi,
>
> I tried this but it didn't work.  It resulted in the class not being
> removed at all.  You can see here:
>
> http://www.toomanydesigns.com/test/noflash/
>
> On Aug 30, 11:20 am, KeeganWatkins <mkeeganwatk...@gmail.com> wrote:
>
> > 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!

Reply via email to