Code Snippets Gallery
Make Entire Div Clickable
$(".myBox").click(function(){
window.location=$(this).find("a").attr("href");
return false;
});Looks for a link inside div with class of “myBox”. Redirects to that links value when anywhere in div is clicked.
Reference HTML:
<div class="myBox">
blah blah blah.
<a href="http://google.com">link</a>
</div>
works very nicely. thanks.
Chris, thanks for this. When I tried this it worked for a hover over empty space in the div but not for the link itself; when I clicked on the link itself it went to a 404 error. Any ideas?
Very cool! Just right now I have used this in my project :D
Very very nice.
I had a job interview today. When asked if there were any blogs I read regularly, I mentioned css-tricks, and the interviewer said that was one of his faves, too.
Great technique.
What if you want to have other links inside the linked div? How would you keep those working still?
this is very useful for my current project
Once again, TOTALLY AWESOME!!!
“window.location” seems not to work in IE if you are using RealURL. Any Ideas?
Thx
Christoph
fixed it this way:
var base = $j(“base”).attr(“href”);
$j(“#menu li a”).each(function(){
$j(this).attr(“href”, base+$j(this).attr(“href”));
});
I think i am going to try this with tables…. Or is there an easier way?
wow … very sweet idea :- )
thanks
Nice work
really helpful