Jquery, get columname when cell clicked -
how can column name jquery when cell clicked?
you can obtaining index of cell, , getting text header same index.
i have uploaded demo here:
http://jsfiddle.net/sohnee/dnxtz/23/
the jquery looks this:
$("td").click(function(){ var $this = $(this); var col = $this.parent().children().index($(this)); var title = $this.closest("table").find("th").eq(col).text(); alert(title); });
and relies on proper table structure....
<table> <thead> <tr> <th>name</th> <th>address</th> </tr> </thead> <tbody> <tr> <td>steve</td> <td>uk somewhere</td> </tr> <tr> <td>scott</td> <td>usa somewhere</td> </tr> </tbody> </table>
note: caption, tfoot et al, omitted optional stuff can added , script still works.
Comments
Post a Comment