- 1

How can i make table of user given input of table and length?

I want to make a table of user input of table and length, where it stops.in JavaScript

12th Jan 2020, 6:56 AM
Moiz Khan
Moiz Khan - avatar
3 Answers
+ 1
After getting required dimensions of table as input : (Say number of rows is M and number of rows is N) 1.Create a table element. let table=document.createElement('table'); 2.create rows and for each rows create cells that will be appended to row for(let i=0;i<M;i++){ let tr=document.createElement('tr'); for(let j=0;j<N;j++) { let td=document.createElement('td'); tr.appendChild(td); } table.appendChild(tr); } notice that you need to append(insertion will also work) to its parent in DOM .without this element won't be added to DOM. after appending all rows and cells to table you need to add table into DOM at its appropriate position . For example you may add it to body directly as: document.body.appendChild(table); Ensure DOM is loaded before script runs. In case you need to change content of cells you can use textContent , innetText or innerHTML properties of element. also read: https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild
12th Jan 2020, 7:10 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
+ 1
Moiz Khan "How to assign a value to a variable" -> See JS course here on sololearn. learn and apply.(I personally suggest learning from javascript.info but as you have joined app try this also) You have completed enough course to understand this. Didn't you find prompt method in course.? As a beginner you MUST try to spend more time writing code. Please first try it yourself. I have explained enough. Efforts from you side matter the most. So go and start learning.
12th Jan 2020, 7:36 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
0
But i am beginner. And how to assign a value to a variable
12th Jan 2020, 7:31 AM
Moiz Khan
Moiz Khan - avatar