tags:

views:

108

answers:

3

hello - 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>  


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



        </ul>
+2  A: 

EDIT:

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

try this;)

dfens
that doesn't work!it should - but it doesn't...
daniel Crabbe
In what way does it fail to work?
Matchu
you forgot about tags_ prefix : $("#tag_"+tagID).parent('ul').attr("id");
dfens
@runge um, I think it is in the tagID at that point
Mark Schultheiss
don't need a prefix as tagID comes out as tag_772...
daniel Crabbe
i get 'undefined' for parentID...
daniel Crabbe
+1  A: 

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'); 
Mark Schultheiss
still undefined - not sure what is going on!
daniel Crabbe
A: 

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>");

    }



});
daniel Crabbe