3

I want to make a whole row a clickable link. I used following code. It is working good. It working by clicking the row. But I couldn't open this with Ctrl+click. How to implement this with the Ctrl clicks?

jQuery(document).ready(function($) {
    $(".clickableRow").click(function() {
        window.document.location = $(this).attr("href");
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<tr class='clickableRow' href='url://'>
    <td>Blah Blah</td>
    <td>1234567</td>
    <td>£158,000</td>
</tr>
GMachado
  • 791
  • 10
  • 24
Akash
  • 295
  • 1
  • 5
  • 19
  • 2
    You will need to determine if it is being pressed at the time of the click. Refer to this post. http://stackoverflow.com/questions/2445613/how-can-i-check-if-key-is-pressed-during-click-event-with-jquery – Brian Dec 12 '14 at 04:32
  • Thank you Brain you gave the way. I fixed it. Thanks. – Akash Dec 12 '14 at 05:00

1 Answers1

3

This is my answer:

  $(".clickableRow").click(function(evt) {
        var url = $(this).attr('href');

        if (evt.ctrlKey) {
            window.open(url, '_blank');
        } else {
            window.open(url, '_self');
        }

It is working good.

Akash
  • 295
  • 1
  • 5
  • 19
  • 1
    Side note assuming you are using HTML 5. You will probably want to use data-href on the tr since href is only valid on the a tag. https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes – Brian Dec 12 '14 at 05:12