HTML - how to make an entire DIV a hyperlink?

Viewed 302694

How do I make an entire DIV a clickable hyperlink. Meaning, I essentially want to do:

<div class="myclass" href="example.com">
    <div>...</div>
    <table><tr>..</tr></table>
    ....
</div>

And whenever someone mouse hovers of the myclass DIV, I want the entire DIV it to be a clickable hyperlink.

7 Answers

You can add the onclick for JavaScript into the div.

<div onclick="location.href='newurl.html';">&nbsp;</div>

EDIT: for new window

<div onclick="window.open('newurl.html','mywindow');" style="cursor: pointer;">&nbsp;</div>

You can put an <a> element inside the <div> and set it to display: block and height: 100%.

alternative would be javascript and forwarding via the onclick event

<div onclick="window.location.href='somewhere...';">...</div>
Related