Make a Div Into a Link
May 25th, 2006 by TrevorIt's easy to make any div into a link by using a bit of javascript. You can use this technique to make any div "clickable". For example, you might want your "header" div to link to your home page. Here's how it's done (Via):
<div onclick="location.href='http://www.example.com';" style="cursor:pointer;"></div>
If you're using a standard Wordpress theme, you can make your header div clickable by using this code:
<div id="header" onclick="location.href='<?php bloginfo('url');?>';" style="cursor:pointer;"></div>

Nice idea! (I just wish it didn’t rely on Javascript…)
This makes life so much easier. Though.. would there be a way to alter the overstate of a link inside the div. I have a table inside and I can’t change that at this time …. the table has a link within to the same page.
Any thoughts?
Why does the first method (the one with Javascript) not work in IE? Anyone know of any IE browser hacks I could use? Thanks!
So good! Thanks!
Excellent technique!
We have used it in a nice new design on our site.
Thanks!
Great, I’ve been wanting to do this for a while.
Thanks
You helped me tremendously. Thanks!
nice. thanks.
i got my links problem solved. thank you.
This does not *really* make the div into a link. It just makes it clickable. If you right click on the div you do not get the menu options to copy the link target or open the link in a new window/tab that you have for *real* links.
So my DIV responds to clicks now, but how do all the buttons in my DIV from bubbling up their click event to the DIV’s handler? I don’t want to add “e.stopPropagation()” to all my contained buttons/links…
Thanks for the help — simple and effective.
[...] Few days ago, I was looking for the best way to make a DIV into a link when I came across this website: Almost Effortless!. The author showed how to make a div a link with a little bit of Javascript (see article). It is actually pretty simple: [...]
thanks for this post! Nice clean and easy.
Great tips thanks!
@Jake: I know it’s an old comment but did you try ‘div table a:hover’ in your css ?
tank you