Skip to content

Instantly share code, notes, and snippets.

@joeybaker
Created April 9, 2012 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeybaker/2347165 to your computer and use it in GitHub Desktop.
Save joeybaker/2347165 to your computer and use it in GitHub Desktop.
jQuery for a clickable element
/* 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