Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-11-11 17:46:17

rondy
New Member
Registered: 2008-10-27
Posts: 2

Index for the current iteration

There is some way to get the “index” for the current iteration inside a form? What I wanna do:

On the fifth iteration, I’d add a css class (named “last”) like this:

<div class="box">...</div> <div class="box">...</div> <div class="box">...</div> <div class="box">...</div> <div class="box last">...</div>

With the index, i would verify if the iteration is multiple of 5…

Sorry for bad english.

Offline

#2 2008-11-11 18:01:09

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Index for the current iteration

Would the zem_nth plug-in do what you need?


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#3 2008-11-11 18:52:11

nemoorange
Plugin Author
From: Washington DC
Registered: 2006-11-29
Posts: 90
Website

Re: Index for the current iteration

If zem_nth doesn’t work out for you, you could try getting it done with jQuery. Based on markup you provided you can put this into the <head> of your page template.

<script type="text/javascript" src="<txp:site_url />textpattern/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$(".box:nth-child(5n)").addClass("last");
});
</script>

I recently wrote a blog post about this simple technique— jQuery’s nth-child selector makes for rainbows. The post has further details, instructions, and an example.


Txp admin themes | dropshado.ws – a blog for design noobs like me

Offline

#4 2008-11-11 20:15:33

rondy
New Member
Registered: 2008-10-27
Posts: 2

Re: Index for the current iteration

Thank you guys, so much. Zem_nht is exacty what I was looking for (JQuery would be my last alternative).

Offline

Board footer

Powered by FluxBB