remove node in a tree does not maintain its level

in my tree that i am making with the help of jquery, if i remove the parent node i want its immediate children to become the parent.

But if the immediate children have sibling/siblings at same level than all the sibling should become a root node .i think it would be more clear with my example.

  • a
    • b
      • c
    • d
    • e

consider this as my tree what i want is if i remove a than b,d,e should become individual root node and c should come under b.

i am pasting my code it does achieve the root node thing but it make c as the same level of b.

       var liFirst = $(spnElement).parents('li:first');
        $(childPrsnt).insertBefore(liFirst);

        $(spnElement).parents('li:first').remove();
        $(childPrsnt).find('li').unwrap('ul:first');

Answers


You only want immediate children (not all descendants), so instead of .find() use .children() here, like this:

var liFirst = $(spnElement).parents('li:first');
$(childPrsnt).insertBefore(liFirst);

$(spnElement).closest('li').remove();
$(childPrsnt).children('li').unwrap();

Also note the use of .closest() instead of .parent() with :first, it's just a cheaper/shorter way to get the same element.


Need Your Help

MongoDB bind_ip error: bind() failed errno:99 Cannot assign requested address for socket

node.js mongodb ubuntu meteor

I want to configure mongodb to allow remote connections from an external ip address like 66.31.123.123.

How can we make a extension live in typo3?

extension-methods typo3 typo3-tca

I created a extension in typo3 and would like to make it live .Can any one explain the step to be follow?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.