(function ($)
{
var classSelected = 'jstree-glow',
$allEls = $('.jstree-search'),
$prevBtn = $("#prev"),
$nextBtn = $("#next");
function moveDown()
{
var $el = $('.' + classSelected),
pos = $allEls.index($el);
if (pos < $allEls.length - 1) {
move($el, $allEls.eq(pos + 1), pos + 1);
}
}
function moveUp()
{
var $el = $('.' + classSelected),
pos = $allEls.index($el);
if (pos > 0) {
move($el, $allEls.eq(pos - 1), pos - 1);
}
}
function move($from, $to, newPos)
{
$from.toggleClass(classSelected, false);
$to.toggleClass(classSelected, true);
$prevBtn.attr('disabled', newPos == 0);
$nextBtn.attr('disabled', newPos == $allEls.length - 1);
}
$(document).ready(function () {
$prevBtn.on('click', function () {moveUp();});
$nextBtn.on('click', function () {moveDown();});
});
}(jQuery));
jsfiddle.net/bullgare/f2QTH/