/    Sign up×
Community /Pin to ProfileBookmark

Table – insertRow()

Hi,
How to add a new row on a table by clicking a button,

Please help

Thank You,

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63Jan 28.2003 — Well here is how you can add a table row in NS6+/Mozilla 1+ browsers.

it is one of the ways.

get the id of the table

var tbl = document.getElementById("tableID");

now create new TR element

var tr = document.createElement("tr");

set attribute values for this tr

tr.setAttribute("style","font-size:8pt;");

Now say you wanted to add a TD element as well.

var td = document.createElement("td");

td.setAttribute("style","width:200pt;");

and say there is some text you want to display in this td element.

td.appendChild(document.createTextNode("its the DOM td");

now follow the hiereachy and add elements upto the table.

tble.appendChild(tr.appendChild(td));

And there you go you have just added table elelments using DOM.

BTW in IE once you have created rows then you can add TD elements and text values

like this

row.inserCell()

cell.innerText="this is IE td";

cheers

Khalid
×

Success!

Help @saju_m spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...