I have a div of 300px fixed height. Inside the div a have a table that has inputs with a larger height which makes the div to scroll(this is my option so i want it to be overflow:auto)..i dont't have more than 300px of space With the keypress event i want somebody to move up and down on the table tds but when he goes to the last visible td, then the div is not scrolling so the users continues to the next td but the td is not visible anymore because of the scroll I want the div to scroll up when he is in the last visible td and scroll in the td.height()
Any suggestions please?
So far i add a class when somebody changes td with up and down keypress
$(document).ready(function() {
$('body').keypress(function(event){
var a = $('#table .borderRed');
if((event.keyCode)=="40"){
a.parent().next().children().addClass('borderRed');
a.removeClass('borderRed');
}
else if ((event.keyCode)=="38"){
a.parent().prev().children().addClass('borderRed');
a.removeClass('borderRed');
}
});
});
The table is inside a container with the height:300px; and overflow:auto; and the first td of the table has a class 1 and that is the class that i am adding..
.borderRed{ border: 1px solid red;}
.container {width: auto; height:300px; overflow:auto;}
HTML
<div class="container">
<table id='table' width='100%'>
<tr>
<td class='borderRed'>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
<tr>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
<tr>
<td>7</td>
</tr>
<tr>
</table>
</div>
Sorry for the indentation. I am new to stackoverflow, and Jquery.. My tds are up tp 16 in order to make the table scroll and test the functionality or just reduce the height of 300px