Skip to content Skip to sidebar Skip to footer

Append Div In Specific Selector And Get The First One

I have a calendar where I select a date matches an array value and than append a div to it with some styling. But the problem now is that when the day = 1 it will also select the d

Solution 1:

Instead of running your code on all td elements, filter them first.

$('.swiper-slide-active td:not(.text-muted)')
  .filter(function() {
    return $(this).text().trim() == splitDate[0].toString();
  })
  .empty()
  .append('<div class="ex-done ex-base">' + splitDate[0] + '</div>');

but keep in mind that you will get the opposite problem when you select the 30th. It will highlight the 30th of the previous month.

So, noticing that the previous/next dates are of different color, i would assume they have a different class, and you should probably use that to identify the current-month dates to filter.


Post a Comment for "Append Div In Specific Selector And Get The First One"