On the form of a table. In the table there is an input "Price" and "Min. Price". when submitting a form, these fields are checked. It is necessary that the price was not less than the minimum price. If the "Price" field is less, then the input class is assigned .check . Next, I want to highlight all input class='check' . and after 5 seconds the backlight disappears. my jquery:

 function lightFields(){ $('#t_sale_order').each(function(){ $(this).find('.check').css({'border-color':'#d8512d'}); setTimeout(function(){ $(this).find('.check').removeAttr('style').removeClass('check'); }, 5000); }); } 

The backlight is executed; the styles are not deleted after 5 seconds. Can i use setTimeout incorrectly?

  • one
    Add another html markup to the question and show the moment when you call lightFields() - Alexey Shimansky
  • @Kley Why remove the class, you get a one-time code. the second time the class will be gone. Maybe we should set the elements of the frame and repaint the frame to its usual color by timeout, without touching the whole classes and style - Mike
  • 2
    this inside setTimeout is not the same this that outside - Grundy
  • @Grundy, so I suspected it. and now how to get to the outside - Kley

1 answer 1

Since this inside setTimeout does not point to an html element, it cannot be used in the same way as within the each function, but it can be saved.

 $('#t_sale_order').each(function(){ var elementsCheck = $(this).find('.check').css({'border-color':'#d8512d'}); setTimeout(function(){ elementsCheck.removeAttr('style').removeClass('check'); }, 5000); }); 
  • Oh, and I asked for html . I wanted to do even more optimally than the removal of the style attribute and other nonsense) - Alexey Shimansky
  • @ Alexey Shimansky, well, the main thing here was anyway wrong this, everything else is not very important and probably important :) - Grundy