is there any way when to go to URL when user click in <td>
.
Asked
Active
Viewed 1e+01k times
8 Answers
48
<td><a href="http://example.com"> </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
-
can you describe full code for onclick , is there any way to change mouse cursor to hand ? – Ata Nov 15 '10 at 08:07
-
1you can change the cursor with css. Such as `td { cursor:pointer; }` – generalhenry Nov 15 '10 at 08:09
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
-
1What 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