Answer the question
In order to leave comments, you need to log in
Why doesn't the last() function work well in jquery?
here is an example jsfiddle.net/0honhzk5
Answer the question
In order to leave comments, you need to log in
It's not a function it's you not doing a good job...
if(event.keyCode == 38){ //Если нажата клавиша 38
var ind = $('.select');
if(ind.index() == 0){ //Если сейчас "выбран" первый li
$('ul>li').first().removeClass('select');
$('ul>li').last().addClass('select'); //Выбрать последний
}
//А затем в любом случае выбрать тот, что выше
$('ul>li.select').removeClass('select').prev().addClass('select');
}
if(event.keyCode == 38){
var ind = $('.select');
if(ind.index() == 0){
$('ul>li').first().removeClass('select');
$('ul>li').last().addClass('select');
}else{
$('ul>li.select').removeClass('select').prev().addClass('select');
}
}
if(event.keyCode == 38){
var
lies = $("li"),
sel = lies.filter('.select').removeClass('select');
;
(sel.index() ? sel.prev() : lies.last()).addClass("select");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question