Reputation: 709
Ok, I have a table and I need to move data in the cells over one cell. For instance in the following table I need the data in cells to move one, as in...cell 6 to move to cell 9 and cell 9 to move to cell 8 8 to cell 7 and so on. So only the outside cells move. Cell number 5 stays still. This all happens onclick of a button. How can this be done? Maybe an array?
HTML
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr><tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr><tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
<button id="moveStuff">Move!</button>
Upvotes: 0
Views: 372
Reputation: 473
Here I move the cell value using the button as you need.
FiddleDemo:Demo
Script:
$(document).ready(function () {
$("#moveRow").click(function () {
var MyRows = document.getElementById("cellMove");
var ninecell = MyRows.rows[2].cells[2].innerHTML;
MyRows.rows[2].cells[2].innerHTML=MyRows.rows[1].cells[2].innerHTML;
MyRows.rows[2].cells[1].innerHTML = ninecell;
});
});
Upvotes: 2