On Sep 8, 10:38�pm, Jayzon <[EMAIL PROTECTED]> wrote: > What I'd like to do: If an input filed is focussed, a price should be > calculated. To keep the script as efficient as possible, I want to > travel up from the input field to thecellabove it (i.e. one row up, > second or thirdcellin that row). My problem is: How can I traverse > the DOM in this way?
I had a similar problem, I post the solution (valid for what I wanted to achieve), maybe could be helpful to you. Regards oreste.parlatano.com Just jquery: $('td').click(function() { var i = $(this).attr('cellIndex'); var t = $(this).text(); var r = $(this).parent().find('td:eq(0)').text(); var c = $(this).parent().parent().parent().find('th').eq(i).text(); alert ('cell text = '+t+'\n'+'1st cell = '+r+'\n'+'col title = '+c); }); The whole page: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en- US"> <head> <title>Table cell</title> <script src="jQuery.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $('td').click(function() { var i = $(this).attr('cellIndex'); var t = $(this).text(); var r = $(this).parent().find('td:eq(0)').text(); var c = $(this).parent().parent().parent().find('th').eq(i).text(); alert ('cell text = '+t+'\n'+'1st cell = '+r+'\n'+'col title = '+c); }); }); </script> <style> body, html {font-family : Arial;} body {background: #333; color: #fff; font-size: 76%; padding: 0 1em;} .tabtit{background: #000000;} .riga{background: #0000ff;} </style> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <table> <thead class="tabtit"> <tr> <th>ID</th> <th>Tipo documento</th> <th>Titulo</th> <th>Ano publica��o</th> <th>Descri��o</th> </tr> </thead> <tbody> <tr class="riga"> <td>1</td> <td>Dossier restauro</td> <td>iygiu</td> <td>kjbikujb</td> <td>kjubiub</td> </tr> <tr> <td>2</td> <td>Notas de campo</td> <td>lalal�o ����</td> <td>wekrjgwergn</td> <td>erhg erh srtyj yl gg</td> </tr> <tr class="riga"> <td>3</td> <td>Esposi�oes</td> <td>��es</td> <td>owqe</td> <td>woeif oqweh oweh woe </td> </tr> </tbody> </table> </body> </html>