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

  • Home
  • SEARCH
  • 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 640207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:55:40+00:00 2026-05-13T20:55:40+00:00

The code below is (hopefully) a minimized testcase of my original problem. I’m trying

  • 0

The code below is (hopefully) a minimized testcase of my original problem. I’m trying to set up a system where you drag list items from the left menu (draggable items) and then drop’em to the box on the right hand side. Once they’re dropped, you should be able to click the “draggable item” text and expand their fieldsets.

The problem is, however, that once you have dropped the items and clicked to expand them (say you have 3 items), the first one will give you 3 alert boxes, the second one will give you 2 and the last one will only give you 1. In other words, from the top, it will give you x alert boxes (where X is the number of items).

Looking at the code, I really can’t figure out why this happens, other than it seems that having the .click stuff inside stop: seems to be related, given the fact that the example on http://api.jquery.com/click/ works fine.

(BTW: The stuff inside the alert box is supposed to be the ID of the item you clicked.)

Any ideas?


<!doctype>
<html>
 <head>
  <title>testcase</title>

  <style type="text/css">
   body { padding: 50px; font-family: Arial; font-size: .9em }
   #column, #data { float: left }
   #column { width: 13% }
   ul, ol { padding: 0; border: 0 }
   li { list-style: none }

   .droptarget { padding: 10px; border: 1px solid #999; height: 10px; width: 350px; margin-right: 1.2% }
   .ui-draggable-dragging, .ui-sortable-helper { background: #f90; width: 100px; display: block }
  </style>

  <script src="http://code.jquery.com/jquery-1.4.1.js" type="text/javascript" charset="utf-8"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>

  <script type="text/javascript">
   function hideAllElements() {
    var elements = $('.dtContent');
    var elementsLength = elements.length

    for (var j = 0; j < elementsLength; j++) {
     elements[j].style.display = 'none';
    }
   }

   var randNum = 0;

   function randNoDups() {
    tmpRand = randNum;

    while (tmpRand == randNum) {
     tmpRand = Math.round(Math.random() * 50000000);
    }

    randNum = tmpRand;
    return tmpRand;
   }

   $(function () {
    var i = 0;

    $(".draggable").draggable({
     connectToSortable: ".sortable",
     helper: 'clone'
    });

    $(".contentGroupList").sortable({
     connectWith: '.contentGroupList',

     stop: function (event, ui) {
      var currentId = ui.item.children(0).attr('id');
      var currentNumber = currentId.split("dt");
      var randomKey = randNoDups();

      ui.item.children(0).attr({
       id: ui.item.children(0).attr('id') + randomKey
      });

      if ((i + 1) == $('.droptarget').children().size()) {
       hideAllElements();

       var $formContainer = $('<fieldset>').addClass('dtContent').attr({
        id: 'fs' + currentNumber[1] + randomKey
       });

       var $table = $('<table>').appendTo($formContainer);
       var $submit = $('<input>').attr({type: 'submit'}).appendTo($formContainer);

       ui.item.append($formContainer);
       ui.item.attr({id: 'listItem' + i});

       $("span").click(function () { alert($(this).attr('id')); });
       i++;
      }
     }
    });
   });
  </script>
 </head>
 <body>
  <div id="column">
   <ul id="draggables">
    <li class="draggable"><span class="dt" id="dt0">Draggable item</span></li>
   </ul>
  </div>
  <div id="contentGroups-1" class="contentGroup">
   <ul class="droptarget sortable contentGroupList"></ul>
  </div>
 </body>
</html>
  • 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-05-13T20:55:41+00:00Added an answer on May 13, 2026 at 8:55 pm

    The problem is probably here:

    $("span").click(function () { alert($(this).attr('id')); });
    

    This will find every span in the document and alert it’s id. Try using the ui object instead:

    ui.item.click(function() {
        alert(this.id);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below for getting a list of child processes on windows
Hopefully a nice and quick one for you... the below code is working fine
Code below works great with aspx view engine, i am trying to convert it
The code below is in C. When given a set of input numbers, it
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is not working as expected to detect if it is in design
The code below shows a sample that I've used recently to explain the different
The code below gives me this mysterious error, and i cannot fathom it. I
The code below works. But if I comment out the line Dim objRequest As
The code below gives an error: Property 'Int32 Key' is not defined for type

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.