Jquery or Javascript that display content based on the date HELP -
jquery or javascript displays content based on specifics date period
so have 3 dates
12/3/2010
12/11/2010
12/20/2010
and
div contents
content 1 should displaying 12/3 12/11
content 2 should display 12/11 12/20
, content 3 should displaying 12/20 there after
first, others said whole thing bad idea you're depending on client machine date/time , correct approach doing in server side.
anyway, guess have reasons here jquery solution.
have such html:
<div class="datediv"><span class="daterange">1/1/2010 1/1/2011</span>i'll visible during 2010</div> <div class="datediv"><span class="daterange">1/1/2011 1/1/2012</span>i'll visible during 2011</div> <div class="datediv"><span class="daterange">1/1/2012 1/1/2013</span>i'll visible during 2012</div>
put date range inside span inside each div class "daterange".
next, have such css have them hidden:
<style type="text/css"> .daterange, .datediv { display: none; } </style>
and finally, script: (jquery)
<script type="text/javascript"> $(function() { $(".datediv").each(function(index) { var srange = $(this).find(".daterange").html(); var arrtemp = srange.split(" "); var dtfrom = new date(arrtemp[0]); var dtto = new date(arrtemp[1]); var dtnow = new date(); if (dtnow >= dtfrom && dtnow <= dtto) $(this).show(); }); }); </script>
test case available here feel free mess around it: http://jsfiddle.net/2bhld/
Comments
Post a Comment