开发者

parent element id

开发者 https://www.devze.com 2022-12-16 17:46 出处:网络
can\'t get the parent id of the list the item is dragged into. I can get the items\' id easily enough and thought i could get the parent from that but can\'t seem to grab it!

can't get the parent id of the list the item is dragged into. I can get the items' id easily enough and thought i could get the parent from that but can't seem to grab it!

 <li id="tag_772" class="tag tagAssigned ui-draggable" >adventurous briefs</li> 

is the li dragged in. Any help much appreciated!

$("li.tag").draggable({ 
        connectToSortable: 'ul.assignedClass',
        helper: 'clone',
        stop: function(event, ui) { 
            projectTags('add',$(this))
        }
    });

    function projectTags(fnc, tag){
        var tagID =  $(tag).attr("id")

        var parentID = $("#"+tagID).closest('ul').attr("id"); /// closest, parent & parents doesn't work?

        $("#fdbk").prepend("<li>fnc:"+fnc+", tag:"+tagID+" < "+ $("#"+tagID).parents("ul:first").attr("id")+"</li>");

    }

html;

<ul id="tags_978" class="assignedClass ui-sortable">

                <li id="existingTag_1029" class="tagAssigned">space </li>  


                <li id="existingTag_1030" class="tagAssigned">light </li>  


                <li id="existingTag_1031" class="tagAssigned">continuous landscape </li>  


                &开发者_JAVA技巧lt;li id="existingTag_1032" class="tagAssigned">structural glass </li>
<li id="tag_772" class="tag tagAssigned ui-draggable" >adventurous briefs</li>  



        </ul>


EDIT:

var parentID = $("#existingTag_"+tagID).parent('ul').attr("id");

try this;)


change the

var tagID =  $(tag).attr("id")

to

var tagID =  tag.attr("id");

This avoids the nested dom parse, and adds the semicolon on the end of the statement. EDIT:for clarity and in addition:

var parentID = $('#'+tagID).parent('ul').attr('id'); 


ok - gone the long way round...

$(document).ready(function(){

    var selectedList;

    $("#tagBrowser").resizable({
        grid: 20,

    });

    $("#tagBrowser").draggable({ 


    });

    $("ul.assignedClass").sortable({
        revert: true,
        items: 'li.tagAssigned', 
        stop: function(event, ui) { 

        },
       sort: function(event, ui) { 
       },
       change: function(event, ui) { 
            $("#fdbk").prepend("<li>change:"+$(this).attr("id")+" </li>");
            selectedList = $(this);
       }

    });

    $("li.tag").draggable({ 
        connectToSortable: 'ul.assignedClass',
        helper: 'clone',
        stop: function(event, ui) { 
            projectTags('add',$(this))
        }
    });


    function projectTags(fnc, tag){
        var tagID =  tag.attr("id");

        var parentID =  selectedList.attr("id"); /// closest, parent & parents doesn't work?

        $("#fdbk").prepend("<li>fnc:"+fnc+", tag:"+tagID+" < "+parentID+"</li>");

    }



});
0

精彩评论

暂无评论...
验证码 换一张
取 消