Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save alanmarcos/8abdeab0ace73b3e3f88 to your computer and use it in GitHub Desktop.
make any element clickable
$('[data-clickable]').css('cursor', 'pointer').on('click', function(){
var $this = $(this),
elm = $'clickable'),
url = elm.trim()? $this.find(elm).attr('href') : $this.find('a').attr('href');
window.location.href = url;
return false;
Copy link


<div data-clickable>
     <p>Lorem ipsum <a href="">dolor sit</a> amet</p>

or for when there's multiple links:

<div data-clickable=".full-url">
     <p>Lorem ipsum <a href="">dolor sit</a> amet consectetuer <a href="" class="full-url">adipiscing elit</a>.</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment