Adding "Next Topic" and "Previous Topic" Buttons to 130 webpages, code not working unless alerted fi
- by John Guise
I have put "Next Topic" and "Previous Topic" ( fixed)on each web page so you can click to move one page back or forward through the web site.
Here is the code:
$(document).ready(function($){
$("#fixed").prepend('');
$("#fixed").prepend('');
$('#nt').css({'position':'relative','top':'0','left':'24px','font-size':'9px'});
$('#pt').css({'position':'relative','top':'0','left':'0','font-size':'9px'});
var fname = document.location.href;
var thistopic = (fname).split('/').pop();
alert(thistopic);
var nexttopic = $('#jsddm li a');
nexttopic.each(function(index) {
var ref = $(this).attr('href');
if (ref == thistopic){
var num =(index)
}else{
return;
}
var flnk =($(nexttopic)[num+1].getAttribute('href', 2));
var blnk =($(nexttopic)[num-1].getAttribute('href', 2));
$('#nt').live('click', function(){
location.href=flnk;
});
$('#pt').live('click', function(){
location.href=blnk;
});
});
});
id=nt is the "Next Topic" Button,id=pt is the "Previous Topic" Button
flnk is the HREF of the next topic page, blnk is the HREF of the prvious topic page.
HREFs are grabbed from - ul#jsddm li ul li a - a large unordered list menu.
This code works correctly if I have the eighth line included "alert(nexttopic)"
If I take this line out (which I want to, as I do not want alert box popping up) - then the code will not work.
Can anybody put me right please, so the buttons work without "alert(nexttopic)" line included