Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set timeout for several objects

i have the following code for multiple flyers that when clicked will display a help text overlay that goes away after 4 seconds. I can get it to show the help text but the timeout doesnt work.

$(".flyercontainer").click(function(){
  $(this).children('.flyerHelp').css('opacity',0.8);
  setTimeout(function(){
      $(this).children('.flyerHelp').css('opacity',0);
  },4000);
})

thanks for your help.

like image 463
helptomout Avatar asked Sep 24 '26 04:09

helptomout


1 Answers

The this in your setTimeOut()'s callback is not what you think it is (it points to the global object, window).

$(".flyercontainer").click(function(){
  var children = $(this).children('.flyerHelp');
  children.css('opacity',0.8);
  setTimeout(function(){
      children.css('opacity',0);
  },4000);
});
like image 54
alex Avatar answered Sep 26 '26 18:09

alex