Alex
Alex

Reputation: 15

Javascript/jquery iframe next/previous navigation

I have like a hundred of html files with names 2.html, 4.html, 6.html, 8.html etc. and i want to make simple "next/prev" navigation with iframe. If user press "next" - html in iframe changes from 2.html to 4.html. Press "prev" - from 4 to 2.

Already tried this solution with increments 2 and -2, but it's not work.

Upvotes: 0

Views: 1255

Answers (1)

ChrisThompson
ChrisThompson

Reputation: 2008

var page = 2;
$(document).ready(function () {
    $('#next').click(function(){
        page += 2;
        $('iframe').attr('src', './'+page+'.html');
    });
    $('#previous').click(function(){
        page -= 2;
        $('iframe').attr('src', './'+page+'.html');
    });
});

Upvotes: 1

Related Questions