in datepicker jquery if you write like this

$('.datepicker').datepicker({ onSelect : function (e) { $('.ui-datepicker-calendar tbody td').each( function () { if(-здесь проверяется совпадение нужного дня с текущим-){ $(this).css('background','#F94545'); } }) } }); 

then all the days that are needed are repainted in the desired background color, and then everything disappears, who knows how to fix it, please help with advice. At first, everything works exactly because if you display an alert, then for each alert you can see that the background changes on the desired dates, and when the alerts stop, the background disappears from red to the default one.

  • Let's start with the fact that you have an incorrectly headed question - the Datepicker works just fine, but you are just trying to change its work in the wrong way :) - Stanislav Belichenko
  • and how will it be right? and what is the error? - misha11
  • I don’t know how it will be 100% right with the datepicker, but it’s better if you add a class to these elements to highlight the date, and you’ve added a design to the class via css styles. - Sultanov
  • in fact, this is the case, I just wrote like that here, but the point here is that after this function, something happens, apparently the days are rebooting and everything flies, and I cannot find a loading event there to change all the necessary dates ( - misha11

1 answer 1

Answering your question in the comments, you need to solve everything through the styles of the datepicker itself, overwriting them, deleting them and so on. The answer to your question is easily searched by Google for the query "datepicker current date color", for example, here . You are invited to hang the handler on the choice of date and each time update the color of the cell with the current date:

 onSelect: function(value, date) { date.dpDiv.find('.ui-datepicker-current-day a') .css('background-color', '#000000'); } 
  • No, there is no current date selection there, but for example, if a person has an appointment for a consultation on May 4 and June 10, when changing dates and months, change the background on these dates - misha11
  • @ misha11 in the sense that you just need some dates (one, two, it does not matter) to highlight on the calendar, right? Regardless of whether they are current (that is, is the date today) and TP? - Stanislav Belichenko
  • yes yes exactly, it is necessary to highlight the days of consultations, per month there can be one or 10, if you put an event on a click of the whole block, then the month transition will work but by clicking on the days it disappears again ( - misha11
  • Then you can still use the code that I gave you above, in the sense that hanging on the onSelect event onSelect for all the dates you need - and as a result, every time the user clicks on a new date, you will have the backlight you want, but immediately, invisibly to the user, reappear. Or you will have to go into the code of the plugin itself, which is not very true methodologically. - Stanislav Belichenko
  • no, it doesn't work (if you put onSelect like this: function () {$ ('. ui-datepicker-calendar tbody td'). each (function () {alert ($ (this) .html ()); $ (this). addClass ('active');})} then as the alert is displayed below it, it is clear that all dates are painted in the color specified for the active class in the CSD, but as soon as the alert ends, all filled dates become not the default, but if you look they have no class active in the element - misha11