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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:28:54+00:00 2026-06-13T11:28:54+00:00

I have a div element ( #receivedInfo ) with p elements inside of it.

  • 0

I have a div element (#receivedInfo) with p elements inside of it. Each p element has a date in it. I managed to take out this date from each element and compare it to the current date.
After I compare each element to the current date, I want to move them in two divs:

  • one to contain all elements that have a date higher than the current date (“.licitatiiActive“)
  • the other to contain all the elements that have a lower date than the current date (“.licitatiiInactive“)

I managed to do the comparison, but all I can move is only one element.

Here is the HTML I use:

<div id="receivedInfo" class="hidden">
    <p>16.10.2012 - <a href="#">test line 1</a></p>
    <p>16.10.2012 - <a href="#">test line 2</a></p>
    <p>16.10.2012 - <a href="#">test line 3</a></p>
    <p>16.10.2012 - <a href="#">test line 4</a></p>
</div>
<div class="licitatiiActive"></div>
<div class="licitatiiInactive"></div> 

And here is the jQuery I use:

var fullDate = new Date();
var twoDigitMonth = (fullDate.getMonth()+1)+"";
if(twoDigitMonth.length==1) twoDigitMonth="0" +twoDigitMonth;
var twoDigitDate = fullDate.getDate()+"";
if(twoDigitDate.length==1)  twoDigitDate="0" +twoDigitDate;
var currentDate = twoDigitDate + "." + twoDigitMonth + "." + fullDate.getFullYear();

var dataLic;
var infoP;

$.each($("#receivedInfo p"), function () {
    var info = $(this).html();
    dataLic = info.split(' - ')[0].trim();
    infoP = "<p>" + info + "</p>";

});
if (dataLic > currentDate) {
        $(".licitatiiInactive").html(infoP);
    } else {
        $(".licitatiiActive").html(infoP);
    }

As mentioned, the result is that only the first p element from div “#receivedInfo” is being moved to the div “.licitatiiInactive“.
How can I adjust this script to move each element of “#receivedInfo” to the proper div?

  • 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-13T11:28:55+00:00Added an answer on June 13, 2026 at 11:28 am

    Relevant part outside loop and same sample date

    I was astonished at first since my debug attempt with chrome dev tools and a console.log showed the same date every time. The reason was that every sample date was / is the same.

    Below you can see a working solution. The var dataLic is filled in the each-loop and its current value is handled by appendDate.

    $.each($("#receivedInfo p"), function () {              
        dataLic = $(this).html().split(' - ')[0].trim();                
        console.log("dataLic", dataLic, "currentDate", currentDate);        
        appendDate(dataLic, currentDate);
    });
    
    function appendDate(dataLic, currentDate){
        if (dataLic > currentDate) {
            $(".licitatiiInactive").append(dataLic +"<br/>");
        } else {
            $(".licitatiiActive").append(dataLic+"<br/>");
        }   
    }
    

    Update bug found and sample online

    It was quite simple to find the bug after i changed the sample dates.
    You are looping over each date with $.each but your code to copy the values is outside the loop. If you put your code (see my function appendDate()) inside the loop every single value will be handled and not just the last one.
    Please take a look at a working solution to copy the elements

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

Sidebar

Related Questions

I have a div element that has an id and this div contains a
I have DIV element which only has a few lines in and a background
I have a div element which is made jquery Resizable. It has alsoResize option
I have a div element. I need to catch a mouse click on this
I have a div element like <div id=move>Something</div> ...that I'd like to move from
I have this div element: <div id=tl style=float:right;width: 400px; height:100px; background-color:Green; overflow-x: scroll;overflow-y: hidden;>
I have a div element, that has no defined width or height. It holds
I have a DIV element which has a jQuery.toggle Event. If I add a
I have a div element, that on click event, a link slides in. This
I have a div element which has these css attributes : HTML <div class=messageContainer></div>

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.