php - Clicking columns in a table -


i building website loads table. have loaded table database , displayed in table on webpage. want able click on specific columns in table. once clicked want selected column(s) highlighted, after being highlighted want button saves clicked columns record in database?

i not sure how new coding in html/javascript/php.

so if click row1 cell1 , row2cell2 want both of them highlight , want click submit button saves data in cells record in database.

<html> <head> <script type="text/javascript">     function myfun(e){       if(!e.target) alert(e.srcelement.innerhtml);       else alert(e.target.innerhtml); }  </script>  </head>  <body>  <table id="tableid" onclick="myfun(event)" border="1"> <tr>  <td>row 1, cell 1</td>  <td>row 1, cell 2</td> </tr> <tr>  <td>row 2, cell 1</td>  <td>row 2, cell 2</td> </tr> </table> </body> </html> 

i guessing need mousevents thats sure of please help?

you use :nth-child() selector, e.g third column:

demo jsfiddle

$('table').find('tr :nth-child(3)').on('click', function(){     alert('third column clicked!'); }); 

you exclude header cell:

$('table').find('tr :nth-child(3):not(th)') 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -