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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:18:49+00:00 2026-06-09T14:18:49+00:00

I’m working on a page that requires constant HTML elements to be added, removed

  • 0

I’m working on a page that requires constant HTML elements to be added, removed and sorted from the DOM. I have a hidden DIV that contains all the blocks of code that I use clone() on and append it to the DOM. sortable() works on list-items already in the DOM, but not on DOM injected list-items after the DOM is done loading. I have the following list, simplified for example purpose:

<ul class="sprite-list">
    <li>
        <a href="#">
            <img src="icon.png">
        </a>
    </li>
    <li>
        <a href="#">
            <img src="icon.png">
        </a>
    </li>
    <li class="sprite-add">
        <a href="#">Add</a>
    </li>
</ul>

I use the following jQuery code:

$('ul.sprite-list').sortable({
    items: 'li:not(.sprite-add)',
    containment: 'parent',
    opacity: 0.7
}).disableSelection();

With that list hardcoded in the page, it works great. But after I cloned the same list into the DOM I can’t seem to drag & drop them.

I’ve read and seen working examples of sortable() working live. I also saw people recommend using .sortable(‘refresh’). So I tried

$('ul.sprite-list').sortable('refresh');

or

$.fn.sortable('refresh');

but all without success. What am I missing here?

edit: I noticed after injecting the cloned code, the list does have the class ui-sortable which all sortable lists get.

edit 2: I don’t know if it’s relevant but I use a seperate function to get the cloned elements:

function cloneElement(element){
    var container = $('#sprite-clone');

    if(element == 'generationContainer'){
        return container.find('.sprite-generation-container').clone(true);
    }
    else if(element == 'groupContainer'){
        return container.find('.sprite-group-container').clone(true);
    }
    else if(element == 'sprite'){
        return container.find('>li:first').clone(true);
    }
    else if(element == 'customForm'){
        return container.find('.customForm').clone(true);
    }
}

Then when it’s needed I use var generationContainer = cloneElement(‘generationContainer’);
I’m not sure if that affects anything though.

  • 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-09T14:18:51+00:00Added an answer on June 9, 2026 at 2:18 pm

    Well the working examples code doesn’t clone, but add new content, so its a different thing.

    Since I cannot see the rest of the code, then I’m only theorizing. Fix could be done by recalling sortable. So if you would put your sortable code inside a function, call it on document ready and then again when a element as been added.

    Example: http://jsfiddle.net/BWkFp/

    HTML

    <ul class="sprite-list">
        <li>
            test 1
        </li>
        <li>
            test 2
        </li>
        <li>
            test 3
        </li>
        <li class="sprite-add">
            <a href="#">Add</a>
        </li>
    </ul>
    

    JS

    MakeUlSortable = function () {
        $('ul.sprite-list').sortable({
            items: 'li:not(.sprite-add)',
            opacity: 0.7
        }).disableSelection();
    };
    
    $(document).ready(function () {
        MakeUlSortable();
    });
    
    $('.sprite-add a').click(function () {
        $(this).before($('.sprite-list li:first-child').clone());
        MakeUlSortable();
        return false;
    });
    

    Hope you get my point. This code works well for me 🙂

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

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to

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.