Identify The Age Of Your Word & PDF Files Using CSS & jQuery


/ Published in: jQuery
Save to your folder(s)

A jQuery plugin that will add a 'new' icon next to files that are newer than X amount of days.


Copy this code and paste it in your HTML
  1. (function($){
  2. $.fn.newClass = function(attr,classname,offset,debug){
  3. var now = new Date();
  4. var day = 1000*60*60*24;
  5.  
  6. return this.each(function(i){
  7. var old = new Date($(this).attr(attr));
  8. var diff = Math.floor((now.getTime() - old.getTime()) / day);
  9. if(diff < offset) $(this).addClass(classname);
  10. if(debug) $(this).append(" - " + diff + " day(s)"); //testing
  11. });
  12. }
  13. })(jQuery);
  14.  
  15. $(document).ready(function(){
  16. $("#content a").newClass("rel","new",90,true);
  17. });

URL: http://www.nealgrosskopf.com/tech/thread.php?pid=58

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.