Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:23:29+00:00 2026-06-18T12:23:29+00:00

I am stepping through each class of .days-due to add a countdown number until

  • 0

I am stepping through each class of .days-due to add a countdown number until the due date. EG: Due in 2 days – Due Date:2/8/2013

I also want it to show negative days past due date.

http://jsfiddle.net/infatti/XeqPT/#base

The days due number is wrong and I cannot understand why?

<ul>
<li>Due in <span class="days-due"></span> days - Due Date is <span class="month">02</span>/<span class="day">08</span>/<span class="year">2013</span></li>
<li>Due in <span class="days-due"></span> days - Due Date is <span class="month">02</span>/<span class="day">10</span>/<span class="year">2013</span></li>
</ul>

function daysUntil(year, month, day) {
  var now = new Date(),
      dateEnd = new Date(year, month - 1, day), // months are zero-based
      days = (dateEnd - now) / 1000/60/60/24;   // convert milliseconds to days

  return Math.round(days);
}

var monthDue = $(this).next('.month').text();
var dayDue = $(this).next('.day').text();
var yearDue = $(this).next('.year').text();

$('.days-due').each(function(){
    $(this).text(daysUntil(yearDue, monthDue, dayDue));
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:23:31+00:00Added an answer on June 18, 2026 at 12:23 pm

    $(this) in your context refers to the window.

    next looks at the siblings. Your spans are not siblings of window.

    Change your selector. Also, your code is looking at only one set of elements but your markup has two.

    Try this

    function daysUntil(year, month, day) {
        var now = new Date(),
            dateEnd = new Date(year, month - 1, day); // months are zero-based
        days = (dateEnd - now) / 1000 / 60 / 60 / 24; // convert milliseconds to days
        return Math.round(days);
    }
    
    $("li").each(function () {
    
        var monthDue = $(this).find('.month').text();
        var dayDue = $(this).find('.day').text();
        var yearDue = $(this).find('.year').text();
    
        $(this).find(".days-due").text(daysUntil(yearDue, monthDue, dayDue));
    
    });
    

    Find all your li elements, and loop through them doing your calculation. Since we’re selecting off li the context of this changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Stepping through the debugger, the BBox object is okay at the entry of the
I would like to implement or use functionality that allows stepping through a Table
I have a project in Java that I am stepping through and when I'm
Is it possible to view the PTX registers when stepping through inline PTX in
In the code below, when I examine the Chars variable while stepping through the
So I'm (remotely) debugging a java/jboss application in Eclipse, stepping through line by line.
Instead of stepping when the user clicks somewhere on the qslider I want to
I'm using a frame grabber class in order to capture and process each frame
This is driving me nuts. I can't work it out stepping through with Firebug
I'm after some advice on the most efficient approach to stepping through a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.