16

is there any way when to go to URL when user click in <td>.

deceze
  • 491,798
  • 79
  • 706
  • 853
Ata
  • 11,530
  • 19
  • 56
  • 97

8 Answers8

45
<td><a href="http://example.com">&nbsp;</a></td>

or

<td onclick="window.location='http://example.com'"></td>
x2.
  • 9,396
  • 5
  • 37
  • 62
5

Bind a Javascript method to the onclick event on the TD, if you are using jQuery you can do this:

$(document).ready(function(){

$("td").click(function(){

    // Perform your action on click here, like redirecting to a new url
    window.location='http://google.com';
});

});
ace
  • 2,091
  • 6
  • 29
  • 39
5

for same window

onclick="window.location('www.example.com')"

for new window

onclick="window.open('www.example.com')";
ArK
  • 19,864
  • 65
  • 105
  • 136
3

either fill the td with an <a> or set it's onclick to window.location = "URL"

generalhenry
  • 16,997
  • 4
  • 46
  • 63
3

If you don't want to have any other element in your td then you can do it this way:

<td onclick="javascript:window.location.href-'http://www.stackoverflow.com'" style="cursor:hand">Stackoverflow</td>
Ramiz Uddin
  • 4,271
  • 4
  • 37
  • 72
2

You can do it like following:

$(document).ready(function(){
    $('#myTd').click(function(){
        window.location= "http://google.com";
    });
});

demo here: http://jsfiddle.net/zainshaikh/4acMG/3/

Zain Shaikh
  • 5,923
  • 6
  • 38
  • 65
2

Some of these answers provide javascript. Please always include a normal (anchor tag) link for visitors who don't have javascript active in their browser.

Damien
  • 1,219
  • 13
  • 23
-1

There are three ways you can do so.

1) <td><a href="http://example.com">Click me</a></td>

2) <a href="http://example.com"><td>Click me</td></a>

3) <td onclick="window.location='http://example.com'"></td>

Ahsan Ahmed
  • 307
  • 4
  • 13
  • 1
    What about a click event handler? Number 2 is not valid HTML. This answer is inaccurate, implies exclusivity, and does not provide explanation for the examples. – llessurt Jun 25 '19 at 14:29