Reputation: 6087
I'm currently trying to write some Javascript to loop through the elements in a table, but was wondering what the best practise was. I could just call .cells[]
on my table object to get all of the cells in the table, but the W3Schools page says that this is not a W3C standard - should I avoid it then?
The other option is to use .rows[]
to get all the rows (which is W3C Standard), then .cells[]
on each of the rows (again, W3C Standard). Basically - how important is it that I stick to W3C Standard methods?
Upvotes: 1
Views: 127
Reputation: 324627
Where the standard exists, it's generally preferable to use it: there's more chance that it's well-supported in all your target browsers and wide adoption of standards helps prevent the proliferation of non-standard proprietary APIs.
This particular case is a no-brainer: the cells
property of a <table>
element isn't supported in Firefox, so you can't use it on the web.
Upvotes: 2
Reputation: 81412
It is of the utmost importance to use standard APIs and properties as defined by the W3C. This ensures cross-browser compatibility, future-proofing and consistency.
Upvotes: 2