jquery/js help

Soldato
Joined
12 May 2007
Posts
3,896
Location
Bristol
Does anyone know how to count specific items with jquery or js?

As an example..

Code:
<div id="accordion">
	<h3>item</h3>
	<div>panel</div>
	<h3>item</h3>
	<div>panel</div>
	<h3>Images</h3>
	<div id="imagesPanel">panel</div>
	<h3>item</h3>
	<div>panel</div>
</div>

I need a way to calculate that imagesPanel is the 3rd panel. Any ideas?
 
Code:
$('#accordion div').each(function(index){
    if(index == 2 && $(this).attr('id') == "imagesPanel"){
        //do something
    }
});
 
I ended up getting it in the end.

I could get the index of an item, but needed to calculate which panel it was...

Each pair counts as 2 towards the index starting from 0.
Each pair counts as 1 for the panels starting from 0.

so as an example, imagesPanel is index 5 and panel 2

So to get the right panel when only knowing the index,
().index()/2-.5
 
Back
Top Bottom