How to make entire Div clickable in javascript

There are lots of method available to make a div clickable in Javascript. But here we have to get the link of anchor tag which is the inner element of div tag and redirect the user to the link using window.location.

Answers 1
  • Make a div clickable using inner anchor tag with javascript

    <!-- HTML -->
    <div class="myBox">
      blah blah blah.
      <a href="">link</a>
    <!-- javascript -->
    $(".myBox").click(function() {
      window.location = $(this).find("a").attr("href"); 
      return false;

    You can make the entire div clickable using the value of href attribute of anchor tag which is child element of div.

  • Back to code snippet queries related javascript