hello..
i want next question when i click on "NEXT" button and Prev question when click on "PREV "button.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted May 20, 2015, 4:39 AM EDT
PrakashRank #6,639 · 260 reputationPosted May 20, 2015, 4:41 AM EDT
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted May 20, 2015, 4:59 AM EDT
Sure thing. Here you go:
HTML:
var divs = $('.mydivs>div');
var now = 0; // currently shown div
divs.hide().first().show();
$("button[name=next]").click(function (e) {
divs.eq(now).hide();
now = (now + 1 < divs.length) ? now + 1 : 0;
divs.eq(now).show(); // show next
});
$("button[name=prev]").click(function (e) {
divs.eq(now).hide();
now = (now > 0) ? now - 1 : divs.length - 1;
divs.eq(now).show(); // or .css('display','block');
});
});