Skip to content

Instantly share code, notes, and snippets.

@alanmarcos
Last active August 29, 2015 14:14
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 alanmarcos/8abdeab0ace73b3e3f88 to your computer and use it in GitHub Desktop.
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 = $this.data('clickable'),
url = elm.trim()? $this.find(elm).attr('href') : $this.find('a').attr('href');
window.location.href = url;
return false;
});
@alanmarcos
Copy link
Author

Usage:

<div data-clickable>
     <p>Lorem ipsum <a href="http://google.com">dolor sit</a> amet</p>
</div>

or for when there's multiple links:

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

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