Skip to main content
Home / Code Snippets / jQuery Code Snippets / Make Entire Div Clickable

Update: this probably isn’t a thing you need to rely on JavaScript for anymore. Since HTML5, this is perfectly valid:

<a href="">

And remember you can make links display: block; so sometimes you don’t even need the div.

But if you absolutely need to use JavaScript, one way is to find a link inside the div and go to it’s href when the div is clicked.

$(".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="">link</a>

Or, you could set a data-attribute on the div and do like:

window.location = $(this).data("location");