Make Entire Div Clickable


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $(".myBox").click(function(){
  2. window.location=$(this).find("a").attr("href");
  3. return false;
  4. });
  5.  
  6. Looks for a link inside div with class of "myBox". Redirects to that links value when anywhere in div is clicked.
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. Reference HTML:
  14.  
  15. <div class="myBox">
  16. blah blah blah.
  17. <a href="http://google.com">link</a>
  18. </div>

URL: http://css-tricks.com/snippets/jquery/make-entire-div-clickable/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.