Clickable DIVs – jQuery plugin

on May 10, 2011
(2 minute read)

Clickable DIVs jQuery plugin will convert anything (<div>, <li>, <p>, etc.) into a clickable object. It is a great way to enhance the usability of your website by increasing the clickable space to your users while avoiding extra HTML markup or a somehow tedious re-coding of your website.

  • Works with JavaScript disabled too (graceful degradation)
  • Works in all modern, mobile and old browsers: Firefox, Chrome, Opera, Safari, Internet Explorer (including IE6), touch screens (iPhone, iPad, Android), etc.
  • Detects if link needs to be opened in a new page or the same one
  • 1 line of code, easy to install (paste the code and add click class to the div)
  • Works with div, li, p, h1 or any other HTML element

I’ve got invites for a free bank transfer!

This small plugin is being used in this website already. This is how my front page looks like:

The red area symbolizes the clickable area where the link would work for users visiting the website. The black square shows you the existing markup of each listed item.

By adding a simple click class to the list element, it inherits the click bind of the <a> in it and everything becomes a link. The plugin will also detect if the link is set to open in a new window. Look at the clickable area after enabling the plugin:

You can see a working demo at the bottom of this page.


You could add this plugin as an external file but since it is so tiny, the best way of doing it is to embed it into an existing .js file.
1. Add this code inside the DOM ready function of your jQuery:

/* Clickable divs - Copyright Xavi Esteve 2011 Dual licensed under the MIT or GPL Version 2 licenses. */
$('.click').css("cursor","pointer").click(function(){var link=$(this).find('a:first');var linkhref=link.attr('href');if(link.attr('target')){var,link.attr('target'));newWindow.focus()}else{window.location=linkhref}return false});

Things I’m buying on Amazon this week

2. Add the CSS class link to any element you want to inherit the click (a <li> for example).

Source code

Feel free to modify and improve the script by going to ClickableDivs at jsFiddle.

Did you enjoy this article? Read it better on

🦁 Brave, the free Chrome alternative that doesn't track you

No comments yet

Follow me for cool new products and interesting findings on graphic design, web development, marketing, startups, life and humor.

/*Twitter*/ !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);;js.src="//";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs"); /*Facebook (function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); = id;js.src = "//";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));*/ /*Google+*/ window.___gcfg = {lang: 'en-GB'};(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;po.src = '';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);})();
Airbnb 25€ discount