Clem Clem - 1 year ago 114
Javascript Question

Table header JavaScript

My question is, how can I get text from header in javascript? So if I click on header I'll get alert with header text...

$("#myTable th").click(function() {
alert(this.text()); //that doesn't work =)

Answer Source
$("#myTable th").click(function() {
  alert($(this).text());  //use $(this)

text() is a jQuery method so you should apply it to a jQuery selector.
this, inside the function handler refers instead to the DOM node

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download