I have an array of elements with the class "job", obtained using getElementsByClassName("job"). I am attempting to "listen" on all the objects in this array. Initially, I assumed this task would be straightforward, but it seems there is something crucial that eludes me.
However, on every iteration of .addEventListener("change", saveJobs()), the function saveJobs gets executed. This behavior is unexpected as it should only occur "onchange."
There are numerous aspects to consider here.
for( let d = 0; d < jobObjectArray.length; d++)
{
jobStorageHolder = JSON.parse(localStorage.getItem("jobStorageArray"));
if((jobArray[d] === undefined) || (jobArray[d] === null)){
break;
} else {
jobArray[d].addEventListener("change", saveJobs());
}
}
Error found at lines 77-85.
In summary:
- The program should add an event listener onchange to all job elements of the specified class.
- The program is expected to store the new job value into local storage.
- The program must refrain from saving jobs during each iteration of the event listener.