jQuery - Avoid code repetition and shorten script

I've got the following line of jquery that targets each category item within my menu and moves the li to the first ul.main_navigation_level_2. The following works but I have to copy and paste it out 10 times for each different category.

$('li#main_navigation_dept_home_and_furniture_furniture ul.main_navigation_level_2')
  .children('li')
  .appendTo('li#main_navigation_dept_home_and_furniture_furniture ul.main_navigation_level_2:first');

The below is my attempt:

$(".main_navigation_level_2").each(function() {
    var menuItem = $(this);
    menuItem.children('li').appendTo(':first-child',this);
});

Answers


this should be it

$(".main_navigation_level_2").each(function() {
    var menuItem = $(this);
    menuItem.children('li').appendTo(menuItem.first());
});

Need Your Help

problem in converting NSString to NSData

iphone objective-c

I want to convert one NSString to NSData. on Using encoding am getting different value in NSData by displaying it using its description property.

Android - Set action for pressing enter

android

I developed a search-bar in my android application, it contains a text-field and a button. Now, if the user press enter in text field it goes to next line, I want to set a action for enter like if ...

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.