jQuery make entire div clickable

Open link if user clicked anywhere in the block.


jQuery(function ($) { // wait while jQuery loads (document-ready)
    $('.block').click(function () { // open the link if user clicked anywhere on block 
        var link_url = $(this).find('a').attr('href');
        var target_attr = $(this).find('a').attr('target');
        if (target_attr == '_blank') {
        } else {
            window.location.href = link_url;


.block {
    display: inline-block;
    padding: 40px;
    margin: 20px;
    border: 2px solid #555;
    background: #ffa;
.block:hover {
    cursor: pointer;
    background: orange;


<div class="block"> <a href="https://www.google.com/">Google link</a>

    <p>Sample text.</p>
<div class="block"> <a href="http://en.wikipedia.org/wiki/Wikipedia" target="_blank">Wikipedia link - opens in new window</a>

    <p>Sample text.</p>

Leave a Reply

Your email address will not be published. Required fields are marked *