/    Sign up×
Community /Pin to ProfileBookmark

Add row to table

I have found one way to add `<td>` to a table. But the `<tr>` adds automagically so I cannot add **data-id** to the `<tr>`

The current result
[url=https://postimages.org/][img]https://i.postimg.cc/wxR57pJd/tr.png[/img][/url]
The desired result

“`
<tr data-id=”1″>
<td data-key=”tsk_subject”>subject1</td>
<td class=”more”>56</td>
</tr>
<tr data-id=”2″>
<td data-key=”tsk_subject”>subject2</td>
<td class=”more”>456</td>
</tr>
<tr data-id=”3”>
<td data-key=”tsk_subject”>subject 3</td>
<td class=”more”>more</td>
</tr>
<tr data-id=”4”>
<td data-key=”tsk_subject”>subject 3</td>
<td class=”more”>more</td>
</tr>
<tr data-id=”5”>
<td data-key=”tsk_subject”>subject 3</td>
<td class=”more”>more</td>
</tr>
“`

The fiddle I used:
http://jsfiddle.net/od2z3eu8/3/

Any tip how I can add data-id on the fly?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@sibertauthorFeb 23.2022 — I think I found the solution:

``<i>
</i>function add(addrow) {
var newrow = id.insertRow();
newrow.setAttribute("data-id","3")
newrow.innerHTML = row;
}<i>
</i>
``
×

Success!

Help @sibert 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 4.27,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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