Arrow key input to change selected row and column in a grid of HTML elements
Ok, after redoing it from scratch, here's a few points to consider:


Instead of checking if the key "exists" check if it's true/false
You can make it more flexible by making the size of the tile a variable (or even better, a variable for height and one for width)
It's better to store the tiles into an array, with their respective x and y variable. This way, you don't have to parse the DOM with jQuery each iteration of the loop, you only loop through the array and select the tile element.


Here's the new code:

HTML - Really simple, just the container for the tiles

&lt;div class="board"&gt;&lt;/div&gt;


CSS - We don't set the size of anything, we'll calculate it with JS

*{
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body{
  background: #f1f1f1;
}

html,
body{
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board{
  display: flex;
  flex-wrap: wrap;
}

.tile{
  background-color: #000;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
}

.active{
  background: #aaa;
}


JS

//amount of tiles horinzontally and vertically
var tileAmountX = 15;
var tileAmountY = 15;


//actual column/row
var actualX = 0;
var actualY = 0;

//size in pixels of the tiles
var tileWidth = 40;
var tileHeight = 40;

//size in pixels of the board, calculated with tile size and tile amount
var boardWidth = tileWidth * tileAmountX;
var boardHeight = tileHeight * tileAmountY;


//array for storing the tiles
var tiles = [];

//keys object, default state are all off (false)
var keys = {left: false, top: false, right: false, down: false};

//set board size style
$('.board').css({
  width: boardWidth + 'px',
  height: boardHeight + 'px'
});

//generate tiles
for(var i = 0; i &lt; tileAmountX; i++){
  for(var j = 0; j &lt; tileAmountY; j++){    

    //create tile and store it in temporary variable
    var el = $('&lt;div class="tile" style="width: '+tileWidth+'px; height: '+tileHeight+'px;"&gt;O&lt;/div&gt;').appendTo('.board');

    //store that variable in the `tiles` array, with the respective `x` and `y` coordinate
    tiles.push({
      el: el,
      x: i,
      y: j
    });    
  }
}

//move to right function, just changes the actualY value and check for overflow
function moveRight(){ 
  actualY = actualY &lt; tileAmountY - 1 ? actualY + 1 : 0;
}

//move to left function, just changes the actualY value and check for overflow
function moveLeft(){
  actualY = actualY &gt; 0 ? actualY - 1 : tileAmountY - 1;
}

//move to top function, just changes the actualX value and check for overflow
function moveTop(){
  actualX = actualX &gt; 0 ? actualX - 1 : tileAmountX - 1;
}

//move to down function, just changes the actualX value and check for overflow
function moveDown(){
  actualX = actualX &lt; tileAmountX - 1 ? actualX + 1 : 0;
}

//generic move function
function move(){
  //get the tiles that have the X or Y coordinate from actualX or actualY
  var starting = tiles.filter(function(val){
    return (val.x == actualX || val.y == actualY);
  });

  //remove the active class for all tiles
  for(var i = 0; i &lt; tiles.length; i++){
    var tile = tiles[i];
    tile.el.removeClass('active');
  }

  //add the active class for the tiles that have the X or Y coordinate from actualX and actualY
  for(var i = 0; i &lt; starting.length; i++){
     var tile = starting[i];
     tile.el.addClass('active');
  }
}

function loop(){

  //this is pretty self explanatory
  if(keys.right){
    moveRight();
  }else if(keys.left){
    moveLeft();
  }

  if(keys.top){
    moveTop();
  }else if(keys.down){
    moveDown();
  }

  //this function runs regardless of the user input
  move();

  //loop with 30fps
  setTimeout(loop, 1000/30);
}

//initiate loop
loop();

//event listener for keydown and keyup
$(window).on('keydown', function(e){
  if(e.keyCode==37){keys.left = true}else if(e.keyCode==39){keys.right = true};
  if(e.keyCode==38){keys.top = true}else if(e.keyCode==40){keys.down = true};
});

$(window).on('keyup', function(e){
  if(e.keyCode==37){keys.left = false}else if(e.keyCode==39){keys.right = false};
  if(e.keyCode==38){keys.top = false}else if(e.keyCode==40){keys.down = false};
});


If you want to see a live example, check this link:

https://codepen.io/tyrellrummage/full/bobxPp/

As you can see, even with a big board (15x15) the motion is very fluid and responsive.

There may be a better way to achieve this, but this is the best I can come up with!