I am working to get a final value from a function, i have two clickable buttons, one is previous and another is next. for clicking both, i am getting the slide show count. to get this result i am using the following codes. it works better, but till i beleave that, there may be a single line solution for this..
can any one correct this code to minimize ?
var tdLength = 7;
var num = 0;
$('a.buttons').click(function(){
num = ($(this).attr('id') == "next-arrow") ? num +=1 : num -=1;
num = ( num > tdLength) ? 1 : num;
num = (num < 1) ? tdLength : num;
alert(num);
})
thanks in advance..
My shot:
The wicked:
Always yields a value in
[1..tdLength](inclusive) for reasonableamountvalues. Inpsired by @Jon answer.