Skip to content

Instantly share code, notes, and snippets.

@pfulton
Created October 30, 2012 18:48
Show Gist options
  • Save pfulton/3982207 to your computer and use it in GitHub Desktop.
Save pfulton/3982207 to your computer and use it in GitHub Desktop.
Make entire "block" clickable
<article class="my-element">
<h1>Article Title</h1>
<p>Teaser text lorem ipsum.</p>
<a href="full-article.html">Read More</a>
</article>
// 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