Pretty new to jquery so this could be a “really man” type of question. But say I have two functions that I want to combine into one but there are slight differences, for example the next() and the prev() methods and the first and last pseudo-selectors are different in each function:
function rotateImage(){
var currentPhoto = $("#photo_slideshow .current");
var nextPhoto = currentPhoto.next();
if(nextPhoto.length == 0){
nextPhoto = $("#photo_slideshow div:first");
}
}
function rotateImage2(){
var currentPhoto = $("#photo_slideshow .current");
var nextPhoto = currentPhoto.prev();
if(nextPhoto.length == 0){
nextPhoto = $("#photo_slideshow div:last");
}
}
There’s got to be a way to combine the two functions to condense the code. Thanks for the help!
You need to provide some argument inside function.something that’ll determine whether next is called or previous is called.do something like this.
While calling:
for next use
rotateImage("next")for previous userotateImage("prev")