Below is the first part of my function where direction is currently an integer used to determine whether to use .prev()
or .next()
.
Is there a way to pass prev
or next
as the parameter direction
?
function nextImage(direction) {
var id = $('#current-image').attr('data-id');
if(direction < 0) {
var ele = $('#' + id).prev();
if(ele.length == 0)
ele = $('#' + id).siblings().last();
}
if(direction > 0) {
var ele = $('#' + id).next();
if(ele.length == 0)
ele = $('#' + id).siblings().first();
}
I feel as though this may not be possible, I have looked at quite a few other resources to try and solve this, though maybe my wording prevented me from finding the solution.