Created
October 30, 2012 18:48
-
-
Save pfulton/3982207 to your computer and use it in GitHub Desktop.
Make entire "block" clickable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<article class="my-element"> | |
<h1>Article Title</h1> | |
<p>Teaser text lorem ipsum.</p> | |
<a href="full-article.html">Read More</a> | |
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// make an entire "block" of content clickable with jQuery. | |
$('.my-element').each(function() { | |
if ($(this).find('a').length !== 0) { | |
$(this).hover( | |
function(){ | |
$(this).css({'cursor': 'pointer'}); | |
}, | |
function(){ | |
$(this).css({'cursor': 'default'}); | |
} | |
) | |
.click(function(){ | |
window.location = $('a', $(this)).attr('href'); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment