| 11:12 pm on Mar 3, 2011 (gmt 0)|
How about nth-child [api.jquery.com]?
| 11:24 pm on Mar 3, 2011 (gmt 0)|
Thanks for this - am I right in thinking though that this is only from IE9?
| 11:28 pm on Mar 3, 2011 (gmt 0)|
No, should work cross-browser, without issue. jQuery programmers (and other open-source contributors) ensure this for you.
| 11:38 pm on Mar 3, 2011 (gmt 0)|
Arh, I didn't know that. I shall give this a go tomorrow when I'm less tired! Just to clarify what do I enter as each of the "div"s in your example
Do I enter the containing div name and then the div block I'm wanting to add the class to so it looks like this:
Thanks for your help with this - very much appreciated.
| 11:47 pm on Mar 3, 2011 (gmt 0)|
You need to read up on selectors. jQuery "mimics" id and class attribute selectors to determine which elements you are targeting. Let's say I have 5 separate <div>s in my html, and within those 5 div elements I have 10 divs each. The code I offered would add the class of "last" to the 3rd div within each of the 5 "parent" div containers.
The way you have it written now would require you to have a class of "divcontainer" on your 5 parent containers (<div>, <p>, etc.) and a class of "divblock" for any containers within them. You can read up on jQuery Selectors [api.jquery.com] for more information.
| 11:49 pm on Mar 3, 2011 (gmt 0)|
| 12:01 am on Mar 4, 2011 (gmt 0)|
You're welcome. I hope that made sense ;)
| 9:39 am on Mar 4, 2011 (gmt 0)|
Just to let you know I added this to my custom js file so that any third div within it's containing div with ID of "results" and class of "grid" will be given a class of "last".
Just in case anyone else needs to know.