user0129e021939232
user0129e021939232

Reputation: 6355

Jquery toggle between divs

Hi I'm currently experimenting with JQuery, my aim is to have a few divs which can be toggled between using arrows. I have a JSFiddle which shows what I have so far, but I think there is a simpler way to achieve what I want to achieve.

I want to be able to keep toggling through the divs when I press the arrows rather than using show and hide.

http://jsfiddle.net/gutigrewal90/ZW3kY/

Any help would be much appreciated!

Upvotes: 0

Views: 395

Answers (2)

Sapan Diwakar
Sapan Diwakar

Reputation: 10966

Here's an updated jsfiddle where you can add as many divs as you want to your DOM now. The solution is to look for next or first sibling of current visible element.

currentElem.hide();
if (currentElem.next().length > 0) {
  currentElem = currentElem.next().show();
} else {
  currentElem = currentElem.siblings().first().show();
}

Upvotes: 1

icr
icr

Reputation: 211

Below is your modified fiddle:

http://jsfiddle.net/hz2nT/1/

regards, Ishan

Upvotes: 0

Related Questions