HTML - how to make an entire DIV a hyperlink?

Teddyk picture Teddyk · Feb 2, 2010 · Viewed 244.1k times · Source

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.

Answer

Joel Etherton picture Joel Etherton · Feb 2, 2010

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>