I have written this code
if (forw == true)
{
if ($('.tickertape li.active')[0] != $('.tickertape li').last()[0])
{
$('.tickertape li.active').removeClass('active').next().addClass('active');
}
else
{
$('.tickertape li.active').removeClass('active');
$('.tickertape li').first().addClass('active');
}
}
else
{
if ($('.tickertape li.active')[0] != $('.tickertape li').first()[0])
{
$('.tickertape li.active').removeClass('active').prev().addClass('active');
}
else
{
$('.tickertape li.active').removeClass('active');
$('.tickertape li').last().addClass('active');
}
}
Which works but really feels like it should only be on one line. This there a way to do this?
A combination of square bracket notation and a conditional operator can be used to choose the property
nextorprev.May be clearer with line breaks…