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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:13:25+00:00 2026-06-01T04:13:25+00:00

I’ve created a list of events in a select it generates the option markup

  • 0

I’ve created a list of events in a select it generates the option markup server-side in php and echo them to client-side. The options created on the server side have just regular attributes and the text between opening and closing option tags, nothing fancy

<option value="myvalue" data-sort="mysortcriteria" class="myclasses">mytext</option>

Using jQuery client side I add an option from a form to the select, using the same string from php for options with different variables in place for attribute values etc. It then sorts the options by date stored in data-sort=”mysortcriteria” which has the same date format. This is the sort function:

var event_list_json = [{date="somedate"},{date="somedate"},{date="somedate"}]
event_list_json.sort( sort_by_date );

where sort_by_date is my custom javascript sort function:

function sort_by_date(a, b) 
{
    return new Date(a.date).getTime() - new Date(b.date).getTime();
}

After it executes it has sorted the select but the old options are sorted with old options and on top new options are sorted with new options but not sorted together… I’m positive I’ve done this before but for whatever reason this isn’t working??? I’m using jQuery UI Selectable but I’m not making any calls through the widget just using native JavaScript.

The output looks like this which other then the extra “style” that somehow gets added to the old options they are identical, but you can see they don’t mix together on sort.

<ol id="selectable" class="ui-selectable">
    <li class="ui-widget-content ui-selectee" data-sort="Mar 22, 2012">Mar 22, 2012 - Dinner in Duncan</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 7, 2012" style="">May 7, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 10, 2012" style="">May 10, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 12, 2012" style="">May 12, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 29, 2012" style="">May 29, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 30, 2012" style="">May 30, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 31, 2012" style="">May 31, 2012 - Breakfast in Victoria</li>
</ol>

The original list looks like this:

<ol id="selectable" class="ui-selectable">
    <li class="ui-widget-content ui-selectee" data-sort="May 12, 2012" style="">May 12, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 10, 2012" style="">May 10, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 7, 2012" style="">May 7, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 30, 2012" style="">May 30, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 29, 2012" style="">May 29, 2012 - Breakfast in Victoria</li>
    <li class="ui-widget-content ui-selectee" data-sort="May 31, 2012" style="">May 31, 2012 - Breakfast in Victoria</li>
</ol>

Here’s what I execute to add the element and sort the parent:

    // Update markup
var event_list_select = jQuery( "#selectable" );
event_list_select.append('<li class="ui-widget-content ui-selectee" data-sort="' + event_date + '">' + event_date + " - " + event_type + " in " + event_location + '</li>');

// Sort json and selector chronologically
sort_html_by_data_attr( event_list_select );
  • 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-01T04:13:27+00:00Added an answer on June 1, 2026 at 4:13 am

    Couldn’t get this to work so I reformatted my code to on remove all children and on AJAX response rebuild the list of events and sort them before they are entered into DOM.

    Worked out better anyway since none of the events had unique ids so I’m able to use the index of the events in the array from the server as the unique id and added this as a data-index=”” attribute. Which is useful for remove specific elements without doing object comparisons.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has

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.