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 8946385
In Process

The Archive Base Latest Questions

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

Ex : Today is 4. Dec December 2012 December 2012 December 2012 Title (5.

  • 0

Ex : Today is 4. Dec

  1. December 2012

  2. December 2012

  3. December 2012

Title (5. December 2012)

Title (7. December 2012)

  1. December 2012

closest date is 5. December (not 3.December) (newer not older)

And If morethan one “5. December” so add class only first-child

HTML :

<div class="wrap">

<div class="zone" id="one">  
<div class="box">
    <footer class="time">1. December 2012</footer>
</div>


<div class="box">
    <footer class="time">1. December 2012</footer>
</div>

<div class="box">
    <footer class="time">3. December 2012</footer>
</div>


<div class="box">
    <h2>Title <span class="time">(5. December 2012)</span></h2>
</div>


<div class="box">
    <h2>Title <span class="time">(7. December 2012)</span></h2>
</div>


<div class="box">
    <footer class="time">9. December 2012</footer>
</div>

</div>

<div class="zone"  id="two">
    <!-- Same .zone#one but i will focus for .zone#one only-->
</div>

</div>


<code></code>

jQuery :

var closest = [];

$('.wrap > .zone:eq(0) .box').each(function(i) {
        var date = $(this).find(".time").html().replace("(","").split(".");
        closest.push(date[0]);
});



$("code").html(closest+"");

Playground : http://jsfiddle.net/WJvZb/

I come to this step now , but have no idea to find closest date and add class it (ex. .closest class)

  • 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-15T12:29:54+00:00Added an answer on June 15, 2026 at 12:29 pm

    You should name your dates in english hence “desember”… Also then you could iterate through your dates and create Date objects from it, then find closest is easy.

    var closest = [];
    
    $('.wrap > .zone:eq(0) .box').each(function(i) {
        var date = $(this).find(".time").html().replace("(","").replace(")","");
            closest.push(new Date(date));
    });
    
    function closestTime(days, testDate)
    {
        var bestDiff = null;
    
        for(i = 0; i < days.length; ++i){
            currDiff = Math.abs(days[i] - testDate);
            if(currDiff < bestDiff || bestDiff == null){
                bestDate = days[i];
                bestDiff = currDiff;
            } else if (currDiff == bestDiff && days[i] > testDate) {
                bestDiff = currDiff;             
            }
        }
    
        return bestDate;
    }
    
    console.log(closestTime(closest,new Date()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a look at the year after setWeek d = Date.today() Wed Dec 26
ruby-1.8.6-p399 :005 > Date.today => Wed, 24393 Dec 2135 ruby-1.8.6-p399 :006 > DateTime.now =>
Today Microsoft released Windows 8 Release Preview and visual studio 2012 rc. I'm a
Today I noticed a snippet of code that looks like the one below: public
Today I started observing some new kind of error which does not allow me
Today I just opened the project I was working on XCODE 4, and only
I want to get the date of the closest Monday in the future (i.e.
I would like to get the date in numbers in Java. For example: today
As an example, I think today, Dec 3 would be 337. Which crystal reports
Today I was perusing my munin graphs and logfiles on one of my VPSes

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.