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

The Archive Base Latest Questions

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

Using the example provided in jQueryUI tutorial: jQuery UI Draggable + Sortable When I

  • 0

Using the example provided in jQueryUI tutorial: jQuery UI Draggable + Sortable

When I drag and drop the draggable <li> element into the sortable list it will be cloned. Which is working as expected. The clone element can then also be re-sorted. This is also working as expected. The problem is that the “click” event of the newly created cloned element doesn’t fire. To illustrate this simply modify the sortable.html by inserting the four lines of code below to the end of the function.

$("li").on("click", function(event){
   var clicked_element_class = $(this).attr('class');
   alert(clicked_element_class);
});
    <!doctype html>

This will trigger an alert showing the element’s class attribute every time a <li> element is clicked. However the alert is not triggered when clicking on the cloned element that has been created by dragging and dropping the draggable element into the list. This shows me that the click event is not fired for a particular clone after this clone has been created and added to the sortable list. It seems actually that the click event has been removed from the clone, or that it is not recognized by the existing $("li").on("click", ... function, since it was added to the DOM at a later point. How can I trigger the same (existing) $("li").on("click", ... function with the alert via the “click” event for a newly created clone in the sortable list? Any help is very much appreciated.

Update:

Here is the entire source code:

            <!doctype html>
            <html lang="en">
            <head>
              <meta charset="utf-8" />
              <title>jQuery UI Draggable + Sortable</title>
              <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
              <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
              <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
              <link rel="stylesheet" href="/resources/demos/style.css" />
              <style>
              ul { list-style-type: none; margin: 0; padding: 0; margin-bottom: 10px; }
              li { margin: 5px; padding: 5px; width: 150px; }
              </style>
              <script>
              $(function() {
                var cloneCache;      
                $( "#sortable" ).sortable({
                  revert: true,
                });
                $( ".ui-state-highlight" ).draggable({
                  connectToSortable: "#sortable",
                  helper: "clone",
                  revert: "invalid"
                });
                $( "ul, li " ).disableSelection();

                $("li").on("click", function(event){
                  var clicked_element_class = $(this).attr('class');
                  alert(clicked_element_class);
                });
               });
               </script>
              </head>
             <body>
  • 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-17T12:28:29+00:00Added an answer on June 17, 2026 at 12:28 pm

    This is because you are only applying the click listener to existing li elements.

    You want to use the selector parameter for the .on() function to add these listeners dynamically:

    Replace this:

    $('li').on('click', function(event) {
        var clicked_element_class = $(this).attr('class');
        alert(clicked_element_class);
    });
    

    With this:

    $('ul, ol').on('click', 'li', function(event) {
        var clicked_element_class = $(this).attr('class');
        alert(clicked_element_class);
    });
    

    Update 1

    To apply this click listener to li and a and p elements change your selector parameter:

    $('ul, ol').on('click', 'li, li a, li p', function(event) {
        var clicked_element_class = $(this).attr('class');
        alert(clicked_element_class);
    });
    

    This applies the listener to li elements, a elements that are children of li elements and p elements that are children of li elements.

    Note this listener will return the class of the each element, not the li class. That is, when an a tag is clicked, the a class will be returned, not the li class.

    Also, perhaps a better way to apply this jQuery on listener is to apply it to the #sortable element:

    $('#sortable').on('click', 'li, li a, li p', function(event) {
        var clicked_element_class = $(this).attr('class');
        alert(clicked_element_class);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the tutorial example code provided by the wikitude SDK and adapting
I have implemented a drag & drop feature using JQuery UI - my current
I'm using JQTOUCH using the AJAX example provided in the demo: $('#customers').bind('pageAnimationEnd', function(e, info){
I am new to JQuery and I am trying to implement JQueryUI resizable into
I have successfully implemented lazy-loading of images in my app using the example provided
I did the query string encryption of my project using the example provided here
Using jQuery/jQueryUI I want to populate a form using this HTML/JS show below. The
I'm running Apache's Hadoop, and using the grep example provided by that installation. I'm
Im using the JqueryUI modal form and since im new to Jquery I figured
I am using the ASP.NET password hashing code example provided in this article. Its

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.