1

I have the following table structure:

<table>
 <tr>
  <th> </th>
  <th> </th>
  <th> </th>

</tr>
<tbody id="page-1">
 <tr>
    <td>  </td>
    <td>  </td>
    <td>  </td>    
</tr>

<tr>
    <td>  </td>
    <td>  </td>
    <td>  </td>    
</tr>
<tr>
    <td>  </td>
    <td>  </td>
    <td>  </td>    
</tr>
<tr>
    <td>  </td>
    <td>  </td>
    <td>  </td>    
</tr>
</tbody>
<tbody id="page-2">
 <tr>
    <td>  </td>
    <td>  </td>
    <td>  </td>

</tr>
<tr>
    <td>  </td>
    <td>  </td>
    <td>  </td>    
</tr>
<tr>
    <td>  </td>
    <td>  </td>
    <td>  </td>    
</tr>
</tbody>
</table>

I have tried the following jquery code to make scroll to specific tbody by id like:

page = 1;
$("#page-"+page).focus() 

The above code failed to make scroll to the specified tbody. I also tried the following in order to get first tr but also failed:

page = 1;
$("#page-"+page+":first-child").focus()

The last thing that I have to mention, that tbody is loaded via ajax request and console.log($("#page-"+page).html()) works fine and prints out the html of the tbody

SaidbakR
  • 13,303
  • 20
  • 101
  • 195

1 Answers1

0

I have got the mistake. focus is not the suitable event for tbody in other words there is no point of focus for it. The solution is Run ScrollTop with offset of element by ID and using:

$('html, body').animate({
                 scrollTop: $('#page-'+page).offset().top -100
                }, 2000);
SaidbakR
  • 13,303
  • 20
  • 101
  • 195