0

I have a problem with my HTML + jQuery code.

I want to set my table row as link to something, but I don't know how to add target="_blank" attribute to this. Anyone can help me fix this?

HTML

<tr class='clickableRow' data-url="http://tbc.designcrown.co.uk/go/siteground">
    <td>Sample</td>
</tr>

jQuery

jQuery(document).ready(function($) {
  $(".clickableRow").click(function() {
        window.document.location = $(this).data('url');
  });
});
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Walter
  • 1
  • 1
  • You could use `window.open`, but it’d be better to just use a proper link – maybe around the contents of each ``. – Ry- Jan 06 '15 at 21:49
  • 1
    @ShaifulIslam why? `data()` method works just fine and is more flexible than using `attr()` – charlietfl Jan 06 '15 at 21:52

1 Answers1

0

You cannot use the target attribute anywhere but on an actual <a /> tag. What you can do is invoke window.open() to create a popup.

For example:

window.open('http://www.stackoverflow.com/','StackOverflow','resizable=1,status=1,menubar=1,toolbar=1,scrollbars=1,location=1,directories=1,width=350,height=350,top=60,left=60')

Here's a tool to generate the appropriate JS: http://www.ricocheting.com/code/javascript/html-generator/popup-window.

Nathan Taylor
  • 24,423
  • 19
  • 99
  • 156