Moving an unordered list using jQuery

This should be easy, but I do not find much online:

I have an unordered list <ul> containing several list items below it <li> , and I would like to address each of them in the list and act on it. How to do it using jQuery?

Thanks.

+4
source share
3 answers

You can use each () for this.

eg.

 $('ul#id li').each(function(index, element) { var li = $(element); // ... }); 
+14
source

Something close to this:

 $('#myulid').children('li').each(function(i, n) { alert($(this).html()); }); 
+3
source

Use this code and modify it if necessary.

 $("ul#id_of_desired_ul > li").each(function() { //do stuff // $(this) references each li }); 
+3
source

All Articles