V
V
vasilseodor2017-03-30 12:15:23
JavaScript
vasilseodor, 2017-03-30 12:15:23

How to show element temporarily on Jquery Cookie?

Tell me how to show an element to a new person using the Jquery Cookie plugin, but not to the old one. But there is a condition - that the old user needs to show the element only for a while. That is, after 24 hours, the old user should not see this element.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad Feninets, 2017-03-30
@fnnzzz

var cookieVal = $.cookie('newUser'});

if(!cookieVal) {
  $.cookie('newUser', Date.now());
}
else {
  var dayInSeconds = 86400
  var currentDate = Date.now()
  var dateDiff = currentDate - parseInt(cookieDate)
  
  if( dateDiff < dayInSeconds ) {
    showElement()
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question