Tuesday 15 June 2010

javascript - Get next table cell vertically in table with rowspans -



javascript - Get next table cell vertically in table with rowspans -

i need find index of cell in table below given cell. imagine don't know td_end, click @ td_start , need find td_end. illustration (need find index of reddish cell(td_end), knowing index of greenish cell (td_start)): http://jsfiddle.net/r5bdw/65/

problem table contain lot of cells rowspan attr, usual searching equal index not work. advice how find such cells?

example table:

<table border="1" style="width: 100%;"> <tr><td>111</td><td rowspan="3">22</td><td>3</td></tr> <tr><td>111</td><td>3</td></tr> <tr><td>111</td><td class="td_start">3</td></tr> <tr><td>111</td><td>22</td><td class="td_end">3</td></tr> <tr><td>111</td><td>22</td><td>3</td></tr> <tr><td>111</td><td >22</td><td>3</td></tr> </table> console.log($('.td_start').index() ) // =1 console.log($('.td_end').index() ) // =2

i think crazy deed guess possible colspan , rowspan combinations.

what seek with, literally "touch" element visually beneath selector element using elementfrompoint

jsfiddle demo

$.fn.nextvert = function(){ var b = this[0].getboundingclientrect(); var nxtv = document.elementfrompoint(b.left, b.bottom+10); if(nxtv.tagname==="td") homecoming $(nxtv); }; $('.td_start').nextvert().text("hello"); console.log( $('.td_start').nextvert().index() ); // 2

by getting elementfrompoint starting this bottom value + tiny offset (i used 10px)

javascript jquery html

No comments:

Post a Comment