krishyalla
krishyalla

Reputation: 27

Adding row data at the top row using Jquery

Here is the code, what it is doing right now is adding data to the table? Here it the sample code..I have the table with data already..when I add another item it should add as a first row...right now it is adding after the existing data..any suggestions..

EDIT

Upvotes: 0

Views: 154

Answers (4)

Milind Anantwar
Milind Anantwar

Reputation: 82241

Use prepend instead of append.

$("#datatable").prepend(tr);

Working Demo

Upvotes: 0

Raidri
Raidri

Reputation: 17550

Use

$("#datatable").prepend(tr);

instead of

$("#datatable").append(tr);

in line 12.

Upvotes: 0

Alvaro
Alvaro

Reputation: 41605

You have to use prepend instead of append.

The .prepend() method inserts the specified content as the first child of each element in the jQuery collection (To insert it as the last child, use .append()).

Upvotes: 0

Marcio Junior
Marcio Junior

Reputation: 19128

Use $("#datatable").prepend(tr);

Demo

Upvotes: 1

Related Questions