javascript - how to focus a custom cell in table? -


i have table , rowselected,i want when user focusout on 4th td 6th td focus instead of td 5.

   var rowindex=$("#mycustomizedtable).attr('rowselected);          var row=$("#mycustomizedtable tbody).find('tr')[rowindex];       var tds=$(row).find('td');       var colselected=$("#mycustomizedtable).attr('colselected');                             console.log(colselected);              

for example : result '4' in console

now,i want 6td focus.

i write have not right answer.

if(colselected==4)    {      $(row).find('td').eq(6).focus();    }    

how can done?

you can refer below code help. here have added focusout listener input elements present in out <table> element. check if focusout happening 4th cell's input or not. , if happening there forcing focus in 6th cell's input box. hope guide achieve goal.

$(document).ready(function(){    $("#mycustomizedtable td input").focusout(function(){      var currentelem = $(this);      var currentindex = currentelem.closest("td").index();      if(currentindex == 3)        currentelem.closest("tr").find(":nth-child(6)").find("input").focus();    });    });  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>  <table id="mycustomizedtable">    <thead>      <th>first</th>      <th>second</th>      <th>third</th>      <th>fourth</th>      <th>fifth</th>      <th>sixth</th>      <th>seventh</th>   </thead>    <tbody>     <tr>       <td><input type="text"/></td>       <td><input type="text"/></td>       <td><input type="text"/></td>       <td><input type="text"/></td>       <td><input type="text" value="5th value"/></td>       <td><input type="text"/></td>       <td><input type="text"/></td>     </tr>     <tr>       <td><input type="text"/></td>       <td><input type="text"/></td>       <td><input type="text"/></td>       <td><input type="text"/></td>       <td><input type="text" value="5th value"/></td>       <td><input type="text"/></td>       <td><input type="text"/></td>     </tr>     </tbody>  </table>  


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo