shortcut - jquery .next() not working properly -



shortcut - jquery .next() not working properly -

im using js shortcut plugin shortcut.js enable keyboard shortcuts , downwards arrows select tabs. when tab clicked, selected. click tab , utilize , downwards arrows take neighboring tab. i'm using .prev() , .next() command selection, wrong .next(). when tab selected, selection skips lastly tab.

jsbin: http://jsbin.com/maqiheja/3/edit?html,css,js,output

js:

shortcut.add("up",function() { $('.tab').each(function(){ var selected = $(this).hasclass('selected'); var end = $('.tab:first-of-type').hasclass('selected'); if((selected === true) && (end === false)){ $(this).removeclass('activetab selected'); $(this).prev().addclass('activetab selected'); } }); }); shortcut.add("down",function() { $('.tab').each(function(){ var selected = $(this).hasclass('selected'); var end = $('.tab:last-of-type').hasclass('selected'); if((selected === true) && (end === false)){ $(this).removeclass('activetab selected'); $(this).next().addclass('activetab selected'); } }); });

you don't need loop. move selected tab next tab once.

shortcut.add("down", function() { var selected = $('.tab.selected'); var end = $('.tab:last-of-type').hasclass('selected'); if (selected.length && !end) { selected.removeclass('activetab selected'); selected.next().addclass('activetab selected'); } }); shortcut.add("up", function() { var selected = $('.tab.selected'); var end = $('.tab:first-of-type').hasclass('selected'); if (selected.length && !end) { selected.removeclass('activetab selected'); selected.prev().addclass('activetab selected'); } });

jquery shortcut next

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -