">
    /    Sign up×
Community /Pin to ProfileBookmark

What javascript changes the table row cell tags from td to

I have a function that dynamically creates a table.

“`
function createDisplayTable(rn,cn)
{
for(var r=0;r<parseInt(rn,10);r++)
{
var x=displayTable.insertRow(r);
for(var c=0;c<parseInt(cn,10);c++)
{
var y= x.insertCell(c);
}
}
}
“`

However, in order to use a JQuery/bootstrap module, I need to change the top row (heading) cell tags from td to <th class=”filter”>

What is the javascript command to change the table top row (heading) cell tags from td to <th class=”filter”>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumSep 03.2020 — IMO it would be best to create the table header separately before the table body, then it would be easy.

If it's not possible to modify the functions try this javascript:
document.querySelectorAll('#id-of-table tr:first-of-type td').forEach(item =&gt; {
const content = item.innerHTML;
const th = document.createElement('th');
th.innerHTML = content;
th.classList.add('filter');
item.replaceWith(th);
});
Copy linkTweet thisAlerts:
@IanRauthorSep 04.2020 — Thanks Sempervivum - Thats great
×

Success!

Help @IanR 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 3.29,
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: @darkwebsites540,
tipped: article
amount: 10 SATS,

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

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...