Upated answer
To create an Array of all links following the click list item.
Markup / the naughty button!
<a class="next" data-role="button" href="" id="" data-inline="true">Next</a>
Code
// Create Array
var links = [];
$('li').on('click', 'a', function (e) {
// Find all links after the clicked link/list item
var list = $(this).closest('li').nextAll('li').find('a');
// Wipe array
links = [];
// Push href and id of each link
if (list.length > 0) {
$.each(list, function () {
links.push({
'href': $(this).attr('href'),
'id': $(this).attr('id')
});
});
}
});
// Next song button
$('a.next').on('click', function (e) {
// Update (Next) button href and id
if (links.length > 0) {
var nexthref = links[0].href;
var nextid = links[0].id;
$('a.next').attr('href', nexthref);
$('a.next').attr('id', nextid);
// Remove used values from Array
links.splice(0, 1);
}
// Move to next song
$.mobile.changePage($(this).attr('href'), {
transition: 'flip'
});
});
Controls - Show/Hide 'Next' and 'Back' buttons (based on my demo)
// Last page
var lastpage = '#' + $('body').find('div[data-role="page"]').last()[0].id;
// Hide 'Next' button / Add button 'Back' button
$(document).on('pagebeforeshow', lastpage, function () {
$('a.next').hide();
$('[data-role=content]').append('<a class="last" data-role="button" href="#songs" data-inline="true">Back to Index</a>').trigger('create');
});
// Remove 'Back' button / show 'Next' button
$(document).on('pagebeforeshow', '#songs', function () {
$('a.next').show();
$('a.last').remove();
});