Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open link when doubleclicking on table row with jQuery

I have a table that looks like this:

<table id="table">
    <thead>
      <tr class='tablehead'>
        <th>Test</th>
      </tr>
    </thead>
    <tbody>
      <tr class='tablecell'>
        <td>
        </td>
      </tr>
    </tbody>
</table>
  1. I want to be able to double click on a row and then trigger a link.
  2. An ID has to be transmitted somehow. Where should I define this? This allows me to edit the selected row afterwards.

Any idea how to do this?

like image 455
nimrod Avatar asked Nov 28 '22 11:11

nimrod


2 Answers

Do you have any jQuery you've written yet? Here's a headstart...

Define your ID in the row:

<tr id="something">...</tr>

Then use something like this:

$('tr').dblclick(function(){
  var id = $(this).attr('id');
  //do something with id
})
like image 85
LeonardChallis Avatar answered Dec 15 '22 08:12

LeonardChallis


This may help you:

jQuery(function($) {
    $('#table tr').click(function() {
        return false;
    }).dblclick(function() {
        window.location = url;
        return false;
    });
});
like image 45
arun Avatar answered Dec 15 '22 07:12

arun