Skip to content Skip to sidebar Skip to footer

How To Append Tr To Top Of Table

how can i append a new tr to the top of the table instead of under other tr. Example:
somethingelse here

Solution 1:

$('table').prepend('<tr><td>something3</td><td>else here3</td></tr>');

or...

$('<tr><td>something3</td><td>else here3</td></tr>').prependTo('table');

More info on 'prepend': http://docs.jquery.com/Manipulation/prepend

More info on 'prependTo': http://docs.jquery.com/Manipulation/prependTo

Solution 2:

This JS is IE specific at the moment, but it shouldn't be too hard to make it multi-browser compatible.

<html><body><scriptlanguage="JavaScript">functionfunction1() {
   var myRow = document.all.myTable.insertRow(0);
   var myCell = myRow.insertCell();
   myCell.innerText = "The added cell"; 
} 
</script><tableid="myTable"border="1"cellspacing="5"cellpadding="5"><tr><tdwidth="100">3</td><tdwidth="100">4</td></tr><tr><td>1</td><td>2</td></tr></table><buttononclick="function1();">Add a cell</button></body></html>

Post a Comment for "How To Append Tr To Top Of Table"