jquery - KeyBoard Navigations -
i attempting have navigation visible on menu user hits key on keyboard.
if no menu item selected, select first instance of class "row", if row-focus exists remove current focus , update next instance of row class "row-focus".
my html formatted:
<div id="group_1386" idgroup="1386" class="group"> <div class="row feed-group-name row-focus" idgroup="1386"> <span class="text">winter coming</span></div> <div class="thetitles ui-sortable"> <div id="feed_26451" class="row t-row"><span class="text">#sgluminis - twitter search</span> </div> <div id="feed_26453" class="row t-row"><span class="text">twitter / mikemagician</span> </div> </div> </div> <div id="group_1387" idgroup="1387" class="group"> <div class="row feed-group-name" idgroup="1386"> <span class="text">summer coming</span></div> <div class="thetitles ui-sortable"> <div id="feed_26451" class="row t-row"><span class="text">summer search</span> </div> <div id="feed_26453" class="row t-row"><span class="text">hot beaches</span> </div> </div> </div>
when clicks "n" on keyboard cycle through elements class of "row". can select next class using .find(), returns more 1 row. can not use .first() because not first. how can find next instance of class row if sibling, child, have class "row".
$(document).on("keypress", null, "n", function(){ if($(".row-focus").length){ var curr = $("#ind-menu").find(".row-focus"); var nextactive = $(curr).siblings().next(".row"); $(curr).removeclass("row-focus"); $(nextactive).addclass("row-focus"); //selected.next().find(".row").next().addclass("row-focus"); } else { //alert("nothing selected"); $("#ind-feeds .row:first").addclass("row-focus"); } });
you have element selected in each set in html- how expect behave when n pressed? if want allow 1 selection per group:
$(document).on("keypress", null, "n", function(){ if($(".row-focus").length){ var curr = $("#group_1386").find(".row-focus"); var allactive = $(curr).parents(".group").find(".row"); var currindex = allactive.index(curr); var nextactive = allactive.eq(currindex == allactive.size() - 1 ? 0 : currindex + 1); $(curr).removeclass("row-focus"); $(nextactive).addclass("row-focus"); } else { $("#group_1386 .row:first").addclass("row-focus"); } });
update handle multiple groups want. or if it's 1 selection per page:
Comments
Post a Comment