TheoretiCAL
TheoretiCAL

Reputation: 20571

How to make table grow upward when dynamically adding rows?

I'm trying to grow a table upward from a fixed position, so that if for example the first table row is at 100px, the next one would be at 110px (grows upward instead of the default downward). How could I achieve this effect if I am dynamically adding table rows?

Upvotes: 2

Views: 222

Answers (2)

MattSizzle
MattSizzle

Reputation: 3175

If I understand correctly and you are wanting to insert new rows into the table, but above the existing rows as opposed to below. This would be a prepend as opposed to an append, and you have a couple of nice jQuery options to do this:

insertBefore:

$('<tr><td>Stuff</td></tr>').insertBefore('table > tbody > tr:first');

before:

$('table > tbody > tr:first').before('<tr><td>Stuff</td></tr>');

prependTo:

$("<tr><td>prependTo</td></tr>").prependTo("table > tbody");

Upvotes: 0

Derek Pollard
Derek Pollard

Reputation: 7165

Use absolute positioning and instead of setting the offset with top use bottom. With this property you can ensure the position of the bottom edge of your div - any change in size will force the div to expand upwards.

Upvotes: 2

Related Questions