views:

64

answers:

2

When someone double clicks on the entire row, I want an alert. How do I bind a double click to an entire row?

+2  A: 

...

$('#table_id tr').dblclick(function(){
  alert('Hello');
});

Note: Using JQuery here, see more info about dblclick here.

Sarfraz
@Alex - Please note that you must download/link to the jQuery framework for this function to work. @Sarfraz - he didn't mention jQuery in his tags, was not sure if he would recognize the syntax.
Tommy
awesome, thanks.
TIMEX
+2  A: 

Well, without jQuery I suppose you could do something like this:

var rows = document.getElementsByTagName('tr'); // you do mean table rows, right?
var length = rows.length;
for (var i = 0; i < length; i++) {
    rows[i].ondblclick = function(){alert('foo');};
}
Bob