Make parent DIV a clickable link using href from a child anchor

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

I had a load of divs with 1 link in and I wanted the div to be act as the link.

(add cursor:pointer to the parent Divs css so peeps know they can click it)

Copy this code and paste it in your HTML
  1. $('.parentElement').bind('click', function() {
  2. // Change window.location (Address) to the url from this element inside it
  3. window.location = $(this).find('.linkClass').attr('href');
  4. });

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.