I have a number of div elements with three class names each. There is an image inside each one. They’re consecutively numbered (i1, i2, i3…) through class names. The class names are something like "img small i14". I need to increment the numbers of these class names for each element.
So: for each of these div elements I need to change the class starting with i – add 1 or subtract 1 from it. Hopefully there is an efficient way of doing this.
The goal of the whole thing is to create a rotating image gallery. I’d much appreciate help, either through helping with the code or offering a better way of approaching the problem. Thank you.
If you combine Pointy’s regExp with undefined’s jQuery attribute setter you get this:
Which works fine (cross browsers i suppose), since the class is an html attribute.
EDIT: To check whether it’s the last image or not you’ll have to know how many images it is in that container, so you’ll have to have a jquery selector that just matches the images in one of the containers.
The code would look like this: