V
V
vvmgev2015-10-03 19:40:38
JavaScript
vvmgev, 2015-10-03 19:40:38

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

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-03
@vvmgev

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'); 
}

Code Max-edition "- Tyk
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'); 
   }
}

-
Code Mini-edition "- Tyk
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 question

Ask a Question

731 491 924 answers to any question