how can I get the position of a cell in a table using javascript? -
By the position I mean, how many columns are on the left side of the cell and how many lines it is above. I really need two functions:
function FindColPos (element) {/ * column find position / return colPos; } FindRowPos function (element) {/ * get row status / / find the row row; }
The function should be written like this, I can not add my document to any item like ID because I have access to the document's head, where I will include JavaScript functions. (This is all part of another project in C #) The element given to the function will have a cell in one line (a & lt; td> gt; element), but it would be better if i < Code> & lt; TD & gt;
and function parent & lt; TD & gt;
. I'm not quite advanced to understand it on javascript, I do not even know it is possible. Hope you can help.
You should be able to iterate over the previous nodes at the same level, and until you run out By doing so, calculate the appropriate nodes.
Something like this
function FindColPos (element) {/ * column position * / var colPos = 0; Var prev = element.previousSibling; While (previous) {if (prev.nodeType == 1 & amp; amp; amp; amp; पूर्व.NodameMatch (/ t [DH] / i) {colPos ++; } Prev = prev.previousSibling; } Return callpost; } Function FindRowPos (element) {/ * Find row status * / var rowPos = 0; Var prev = element.parentNode.previousSibling; While (previous) {if (prev.nodeType == 1 & amp; amp; amp; east.NodameMatch (/ tr / i)} {rowPos ++; } Prev = prev.previousSibling; } Return line pauses; }
colPos
and rowPos
will be indicator if all the elements of the same type are considered as zero-based array < / P>
Edit: For clarity only, both cells are considered to take a cell as an element.
edit2: In this method, the merged cells are counted as one if you need to count the merged cell as pieces instead of a whole, then on any element You can see the colspan
attribute.
edit3: FindRowPos
was closed from 1, now fixed.