简体   繁体   中英

Javascript table / row select

I am asking to help me in following issue: I have a table created in Javascript by

document.createElement('table')
document.createElement('tr')
document.createElement('td')

The table is a web-calendar / organizer. So, I need the top row to display both dates and days in the cells. For now I have a code which displays only dates there. But how can I refer to the cells to put there names of days?

I must say that ONLY native Javascript is available to use (no JS libraries or whatever)! If the table had been created by HTML code I'd have referred to its top row manually via data attribute.

But I've got no idea about what should I do in the current situation.

Any help will be appreciated!

Try this:

var currentTd = document.createElement('td');

Now you've got a variable you can use and you give it an id:

currentTd.id = 'td1';

Later you can use getElementById('td1') and put in the days of the week.

or you can refer to it now before sticking it into the dom:

currentTd.innerHTML = 'Saturday 11th January';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM