jQuery - auto focus textbox by Norlihazmey Ghazali

http://stackoverflow.com/questions/32430494/how-to-traverse-between-td-and-tr-element/32430682?noredirect=1#comment52726550_32430682

HTML

<table>
    <tr>
        <td>
            <input class="inp" />
        </td>
        <td>
            <input class="inp" />
        </td>
    </tr>

  
</table>
<button id="btn">Click me</button>

JavaScript

$('.inp').first().focus();
var all = $('.inp');
var index = (all.index(all.first()) + 1);

$('#btn').click(function () {
    if (index == all.length) index = 0;
      all.eq(index).focus();
    index++;
});