Make element disappear according to system date

Asked

Viewed 34 times

0

I have several boxes with dates in html, example:

<div id="agenda">
  <a href="javascript:void" class="web-thumb">
     <span class="data">13 set</span>
     <span class="hora">10h30</span>
     <p class="tema green-sage">eSocial</p>
  </a>
  <a href="javascript:void" class="web-thumb">
     <span class="data">13 set</span>
     <span class="hora">14h</span>
     <p class="tema green-sage">eSocial</p>
  </a>
  <a href="javascript:void" class="web-thumb">
    <span class="data">14 set</span>
    <span class="hora">10h30</span>
    <p class="tema green-sage">eSocial</p>
  </a>            
</div>

I need to see jQuery the boxes with date lower than the system disappear.

  • 2

    Lower date, you say, is the current date?

  • The lower date is the one displayed within the <span class="date">

  • 1

    Yes, but I will compare it to what other date, exactly? The current date?

  • That’s right! The current date.

1 answer

1


Using Moment js., and jQuery, this is very simple.

$("a.web-thumb").each(function() {
    var data_atual = moment();
    var data_teste = moment("13/09/2016", "dd/MM/yyyy"); // Aqui eu coloquei fixo, mas você 
                                                         // pode usar, por exemplo, 
                                                         // $(this).find("span.data").text(), 
                                                         // mas no formato "13/09/2016", e não 
                                                         // "13 set", como na pergunta.
    if (data_teste.diff(data_atual) < 0) 
    {
        $(this).hide();
    }
});

Place this event on $(document).ready(function() { ... }).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.