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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:19:48+00:00 2026-05-16T11:19:48+00:00

I’ve got a UL of items using jQuery UI that I have drag and

  • 0

I’ve got a UL of items using jQuery UI that I have drag and drop capable. However, I also need to be able to click on one of the items in the list and trigger off a little routine that adds a header line above one of the “li”s. The problem lies with the click on the drag and drop. I’ve tried to bind the click to a specific region of the li using a span but then I lose the index of the li. Here’s my code, any suggestions would be greatly appreciated:

<script type="text/javascript">
 $(function() {
        var item_positions = $('#ml_organize').sortable('toArray');
  $('#ml_organize').sortable({
      placeholder: 'ui-state-highlight',
            cursor: 'pointer'
  });
  $('#ml_organize').disableSelection();
        $('#org_submit').click(function() {
            var item_positions = $('#ml_organize').sortable('toArray');
        });
        $('#ml_organize li').bind('click', function() {
            var rowNo = $(this).index();
            var newRow = "<li id=\'li" + rowNo + "\' class=\'ui-state-default\'><span class=\'icon ui-icon ui-icon-minusthick\' title=\'Remove header line\' alt=\'Remove header line\' onClick=\'removeMLRow(" + rowNo + ");\'></span><span class=\'note\'>HL</span><input class=\'header_line\' maxlength=\'75\' type=\'text\' name=\'hl_text[" + rowNo + "]\' id=\'hl_text" + rowNo + "\' /></li>";
            //alert(rowNo);
            $('#ml_organize li').eq(rowNo).before(newRow);
            $('#hl_text' + rowNo + '').focus(function() {
                $(this).css('background','#DDD');
            });
            $('#hl_text' + rowNo + '').blur(function() {
                $(this).css('background','#FFF');
            });
            $('#hl_text' + rowNo + '').focus();
            // renumber rows after insert
            $('#ml_organize li').slice(rowNo - 1).each(function() {
                var newID = 'li' + ($(this).index() + 1);
                $(this).attr('id',newID);
            });
            var item_positions = $('#ml_organize').sortable('toArray');
            // alert(item_positions);
        });
 });
    function removeMLRow(rowNo) {
        $('#ml_organize li').eq(rowNo).remove();
        // renumber rows after remove
        $('#ml_organize li').slice(rowNo).each(function() {
            var newID = 'li' + ($(this).index() + 1);
            $(this).attr('id',newID);
        });
        var item_positions = $('#ml_organize').sortable('toArray');
        //alert(item_positions);
    }
    $('#org_submit').button();
</script>

And here’s the UL that it needs to manipulate:

<ul id="ml_organize">
   <li id="li1" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">2</span><span class="org_partno">RFCH702</span><span class="org_desc">HEAVY HARDWARES(PAIR) 2.0" STGR</span></li>
    <li id="li2" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">2</span><span class="org_partno">FBM26CB</span><span class="org_desc">FLR BASE MLDINGX26" (CB VINYL)</span></li>
    <li id="li3" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">2</span><span class="org_partno">AFC2202DG</span><span class="org_desc">AUX CHANNEL, 4¿</span></li>
    <li id="li4" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">601343874</span><span class="org_desc">UNI-STRUT KIT - ED8C509-50 G9 EQUIVALENT</span></li>
    <li id="li5" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">4</span><span class="org_partno">ISS888</span><span class="org_desc">INSUL STRIP FOR BAYS-42" LONG</span></li>
    <li id="li6" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">4</span><span class="org_partno">ICS775</span><span class="org_desc">INSUL CABLE RACK 1.5"STG 7.75"</span></li>
    <li id="li7" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">2</span><span class="org_partno">CJB6302C</span><span class="org_desc">CLIP J-BOLT ASSM FOR 2"CR/FC</span></li>
    <li id="li8" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">TR53</span><span class="org_desc">5/8-11 THREADED ROD X  24.0"</span></li>
    <li id="li9" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">MAS-NTWKBAYKIT</span><span class="org_desc">FLOOR MNTG HARDWARE KIT (NTWK)</span></li>
    <li id="li10" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">ESD1080740001</span><span class="org_desc">ESD BANANA JACK</span></li>
    <li id="li11" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">ESDSTRAP</span><span class="org_desc">ADJ ELASTIC 63070</span></li>
    <li id="li12" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">ESDLABEL</span><span class="org_desc">GREEN .75" X 1.75" ESD LABEL</span></li>
    <li id="li13" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">SPT6224</span><span class="org_desc">SPLIT TUBE 5/8" X 24" GRAY</span></li>
    <li id="li14" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">SAF2502</span><span class="org_desc">FRAMING CLIP ASSM AUX CHNL 5/8</span></li>
    <li id="li15" class="ui-state-default"><span class="icon ui-icon ui-icon-plusthick" title="Add header line" alt="Add header line"></span><span class="org_qty">1</span><span class="org_partno">T1523-0031-200</span><span class="org_desc">28 PR/24AWG SHLD, AMP 64-PIN FEMALE CONN</span></li>
</ul>
  • 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-16T11:19:49+00:00Added an answer on May 16, 2026 at 11:19 am

    See if the below solves the problem.

    Note that I tried to clean up the code a bit as well, but it could still be a lot simpler. You don’t need all the separate IDs for each LI, since you are using index() — I removed them from the JS.

    Couple of other points:

    • If you will end up with hundreds or thousands of LIs, you should use event delegation rather than binding to click (event delegation might simplify this code further anyway).
    • For elements handling clicks, it’s usually nicer/better to use rather than . You can then at least have them do something for people without JavaScript.
    var mlo, item_positions, numAdded;
    var disableAdd = false;
    $(function() {
        mlo = $('#ml_organize');
        mlo
            .sortable({
                placeholder: 'ui-state-highlight',
                cursor: 'pointer',
                start: function() {
                    disableAdd = true;
                },
                stop: function() {
                    setTimeout('disableAdd = false', 1000);
                }
            })
            .disableSelection();
            .find('li')
                .click(addMlRow);
    
        item_positions = mlo.sortable('toArray');
    
        $('#org_submit')
            .click(function() {
                item_positions = mlo.sortable('toArray');
            })
            .button();
    });
    
    function addMlRow() {
        if(disableAdd) return false;
        var that = $(this);
        var rowNo = that.index();
        numAdded++;
        $('<li id="new' + numAdded + '" class="ui-state-default"><span class="icon ui-icon ui-icon-minusthick" title="Remove header line"></span><span class="note">HL</span><input class="header_line" maxlength="75" type="text" name="hl_text[' + rowNo + ']" id="hl_text' + rowNo + '" /></li>')
            .insertBefore(that)
            .find('span.ui-icon-minusthick')
                .click(function() {
                    $(this).parent().remove();
                    item_positions = mlo.sortable('toArray');
                })
            .end()
    
            .find('input')
                .focus(function() {
                    $(this).css('background','#DDD');
                })
                .blur(function() {
                    $(this).css('background','#FFF');
                })
                .focus();
    
        item_positions = mlo.sortable('toArray');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I have just tried to save a simple *.rtf file with some websites and
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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 want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.