I've got some javascript code referencing
var cell = event.target
if (cell.cellIndex === 3) {
...
}
Is the cellIndex property safe to use?
What would be a good cross-browser alternative?
jQuery is allowed.
cellIndex
is supported by all major browsers[src] and is defined in DOM level 2[src]. Stick with that. In jQuery, you can use:
$('#myTD')[0].cellIndex;
jQuery's index()
might also be optimized to make use of would also work, though it would be less efficient because it works by getting an array of the parent node's children and finding the index of the current element in that array.cellIndex
where available,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With