views:

175

answers:

2

I am creating a tabbed content interface. The content panels are an unordered list created using a server-side script. I want to add tabs via jQuery to control the panels. The only requirement for the jQuery plugin to work is to have the same amount of panels as tabs (the number of panels isn't always consistent). I need to query how many list items are in my ul.panels and store it in a variable, so I can create a loop with that variable to append my list items in ul.tabs.

I don't have access to the server-side script, so modifying the PHP isn't a possibility.

+2  A: 

Like this?

 var cnt = $('ul.panels li').length

jQuery hangs varous things off of it so you don't really need your own loop (methinks). You could do this too:

 $('ul.panels li').each( function(idx, panel) {
     // stir in special sauce
 });
seth
You are absolutely correct. I marked the other question as correct, since it came in first. However, the method you described in your second half is exactly what I'll be using, since it'll be killing 2 birds with one stone. Much better implementation than what I was planning on doing. Thanks for your input.
mikemick
+1 for helping asker find a cleaner solution.
sixthgear
@sixthgear - Thanks! :)
seth
A: 
var count = $("ul.panels li").size();
sixthgear