I have code which I don't want to nearly copy paste, instead I want an short alternative.
I have this 4 elements, which all should be manipulated, I want to place an Input inside them and edit some arguments.
Now I want to run the same code for each of these 4.
const tableTaskName = document.getElementById('taskName_' + taskID);
const tableStartTime = document.getElementById('startDate_' + taskID);
const tableEndTime = document.getElementById('endDate_' + taskID);
const tableStatus = document.getElementById('status_' + taskID);
Below are examples where I used tableTaskName.
The task is the parameter my function takes, and is one task of the tasks Array on the bottom.
The type should be text for tableTaskName and tableStatus, for tableStartTime and tableEndTime it should be time.
tableTaskName.innerHTML = ''
tableTaskName.textContent = task.taskName;
const inputTaskName = document.createElement('input');
inputTaskName.type = 'text';
var tasks = [{ 'id': 1, 'taskName': 'INIT', 'startDate': new Date('1970-01-01T00:00:00Z'), 'endDate': new Date('1970-01-01T00:00:10Z'), 'duration': new Date('1970-01-01T00:00:10Z'), 'status': 'RUNNING'},
{ 'id': 2, 'taskName': 'INIT', 'startDate': new Date('1970-01-01T00:00:00Z'), 'endDate': new Date('1970-01-01T00:00:10Z'), 'duration': new Date('1970-01-01T00:00:10Z'), 'status': 'RUNNING'} ]
Is the only possible method to take copy paste the code? I'd like to do it without that, if possible.