Skip to content
Advertisement

Loop doesn’t work when exported with ParcelJS

I am using ParcelJS V2. I have the following code that gets data from an HTML table. Every <td> in the cell consists of an <input> tag and the getElementById refers to the ID of the input tag.

getCount.js

JavaScript

script.js

JavaScript

When I check my console, there isn’t log from the collectData function.

This FOR loop works fine when I use it in my script.js but doesn’t work when I export and then import into script.js.

Are there any ways to export loops using ParcelJS?

Advertisement

Answer

Move

JavaScript

inside your function collectData() {.

At the time of bundling the DOM is unavailable, rendering your rowCount undefined.

When your function is being executed, your loop end condition checks

JavaScript

undefined - 2 results in NaN.

JavaScript

is false, so your loop never runs.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement