jqueryjquery-draggablejquery-droppable

how to drag only child elements inside nested ul tags using jquery ui draggable


My list is something like this
<div id="jqxTree">
    <ul>
        <li>Parent1
            <ul>
                child1
            </ul>
        </li>
        <li>Parent2
            <ul>
                child2
            </ul>
            <ul>
                child2.1
            </ul>
        </li>
    </ul>
</div>

when i use jquery draggable its dragging entire list.How to i drag only child1,child2,child2.1 elements .To generalise i wanna drag only li elements inside ul which is inside li..

I tried using the below function but on mouseover the elements of li the elemnts get hidden

$('#jqxTree').delegate('li li', 'mouseover', function () {
    $(this).draggable({
        revert: true,
        revertDuration: 0
    });
}); 

Solution

  • According to jQuery API page:

    As of jQuery 1.7, .delegate() has been superseded by the .on() method.

    Fiddle Demo

    jQuery:

    $(function () {
        $('#jqxTree').on('mouseenter mouseover', 'li > ul', function () {
            $(this).draggable({
                revert: true,
                revertDuration: 0
            });
    
        });
    });
    

    In CSS, use > between parent and child elements.

    Also you had li li instead of li ul.