/    Sign up×
Community /Pin to ProfileBookmark

Insert new row table

hello guys,

i need your help to solve my problem. i don’t know how to insert new row in the table using javascript?

plz guys help me…..

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesMay 13.2005 — The best method:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>

<script type="text/javascript">
<!--
if (document.getElementById) onload = function () {
document.getElementById ('foo').className = 'hide';
setTimeout ("document.getElementById ('foo').className = ''", 1000);
}
// -->
</script>

<style type="text/css">
<!--
th, td {background-color:#aaa; color#000; padding:1ex; text-align:center}
.hide {display:none}
-->
</style>

</head>
<body>
<table summary="some poor example">
<thead>
<tr><th scope="col">Heading</th><th scope="col">Heading</th><th scope="col">Heading</th>
</thead>
<tbody>
<tr><td>Data</td><td>Data</td><td>Data</td></tr>
<tr id="foo"><td>Data</td><td>Data</td><td>Data</td></tr>
<tr><td>Data</td><td>Data</td><td>Data</td></tr>
</tbody>
</table>
</body>
</html>
Copy linkTweet thisAlerts:
@CharlesMay 13.2005 — Makes your page JavaScript dependant, which is very bad:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>

<script type="text/javascript">
<!--
if (document.getElementById) onload = function () {
var tr = document.createElement ('TR');

<i> </i>var td1 = document.createElement ('TD');
<i> </i>var text1 = document.createTextNode ('New Data');
<i> </i>td1.appendChild (text1);
<i> </i>tr.appendChild (td1);

<i> </i>var td2 = document.createElement ('TD');
<i> </i>var text2 = document.createTextNode ('New Data');
<i> </i>td2.appendChild (text2);
<i> </i>tr.appendChild (td2);

<i> </i>var td3 = document.createElement ('TD');
<i> </i>var text3 = document.createTextNode ('New Data');
<i> </i>td3.appendChild (text3);
<i> </i>tr.appendChild (td3);

<i> </i>document.getElementById ('foo').appendChild (tr);

}
// --&gt;
&lt;/script&gt;

&lt;style type="text/css"&gt;
&lt;!--
th, td {background-color:#aaa; color#000; padding:1ex; text-align:center}
.hide {display:none}
--&gt;
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;table summary="some poor example"&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th scope="col"&gt;Heading&lt;/th&gt;&lt;th scope="col"&gt;Heading&lt;/th&gt;&lt;th scope="col"&gt;Heading&lt;/th&gt;
&lt;/thead&gt;
&lt;tbody id="foo"&gt;
&lt;tr&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @shmunaz 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...