17

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

deceze
  • 510,633
  • 85
  • 743
  • 889
Ata
  • 12,126
  • 19
  • 63
  • 97

8 Answers8

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

or

<td onclick="window.location='http://example.com'"></td>
x2.
  • 9,554
  • 6
  • 41
  • 62
6

for same window

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

for new window

onclick="window.open('www.example.com')";
ArK
  • 20,698
  • 67
  • 109
  • 136
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,141
  • 7
  • 29
  • 39
4

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,249
  • 4
  • 40
  • 72
3

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

generalhenry
  • 17,227
  • 4
  • 48
  • 63
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
  • 6,013
  • 6
  • 41
  • 66
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
  • 327
  • 5
  • 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