when i sorting the child, I have got value of parent and child but it will comes like (title1orangepinkyellowgreen, title1orangepinkyellowgreen, title1orangepinkyellowgreen, title1orangepinkyellowgreen), but i have to print it like this way (Title1_orange, title_pink...)
var addPositions = function() {
$('.droptrue, .droptrue1').each(function() {
var position = 0;
$(this).children().each(function() {
$(this).data('position', position);
position++;
});
});
};
$(document).ready(function() {
var treeList = "";
treeList = "<ul id=\"createTree\" class=\"droptrue1 mt1\">";
for(var key in jsonObj){
//alert("key: " + key + ", value: " + jsonObj[key])
for (var skey in jsonObj[key]) {
treeList += ("<li class=\"listTree\" id=\"asdf\">"+skey +"<ul class=\"droptrue mt\">");
for (var sskey in jsonObj[key][skey]){
for (var ssskey in jsonObj[key][skey][sskey]){
treeList += ("<li class=\"innerList\">"+jsonObj[key][skey][sskey][ssskey]+"</li>");
}
}
treeList += "</ul></li>";
}
}
treeList += "</ul>";
$('#tree').append(treeList);
addPositions();
$(".droptrue").sortable({
connectWith: "ul.mt",
dropOnEmpty: true,
stop: function(event, ui) {
var order = [];
ui.item.closest('ul').children('li').each(function() {
order.push($(this).data('position'));
var c = $(this).text();
var z = $(this).parents().eq(1).text();
alert(z);
$("#cl").append(z+"<br />");
});
}
});
Here fiddle link: http://jsfiddle.net/thilakar/VKWeC/
Thanks
Like i suggested above, maybe try to add a span since that title is basically the lists sibling "ul" portion.
You can also use prev() instead of siblings. It really depends how complicated your html is going to hey. There is also find().