Created
April 9, 2012 22:50
-
-
Save joeybaker/2347165 to your computer and use it in GitHub Desktop.
jQuery for a clickable element
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
/* Clickable elements | |
*/ | |
// when any .clickable elem is clicked, we'll grab the first link in the elem and redirect to it. | |
$('body').on('click', '.clickable', function(e){ | |
var link = $('a:first', this) | |
, href = link.attr('href') | |
// _blank, command key, ctrl key, middle click | |
if (link.attr('target') == '_blank' || e.metaKey || e.ctrlKey || e.which == 2) | |
window.open(href, '_blank') | |
else | |
window.location = href | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment