Reputation: 13672
All,
I need to scrape an HTML table into a JS array. Is there a difference between exploring the table using the DOM table elements (e.g., table.tBodies[0].rows[0].cells[0]
) and looping through the cells using their IDs (e.g., document.getElementById('cell_i')
)?
Upvotes: 1
Views: 119
Reputation:
Using the table member collections provides short, clear and idiomatic code, and there are no browser compatibility issues to my knowledge.
Certainly, getElementById()
would work, but you'd need to identify every member, or at least every cell, and that would seem cumbersome. Plus then you'd need some logic to ensure you're using the correct ID.
Both the collection lookups and the getElementById()
will be very fast. I doubt you'll find any compelling gain either way.
Upvotes: 3