Make Div Open a Link onClick

Sometimes there are situations that you want a div to be a clickable element but it should not be a link. An example is the website that I’m currently working at. A box with images and text have to go to a certain page when click. This is a div and I can’t put text and image inside an <a> tag. Actually I can, it but it’s a bad practice and forbidden.

Thanks to the power of JavaScript! Using the code below you can make a div clickable onClick.

When someone click that box it will go to monstertut website.

You may also add some style to your clickable div.

We need to add the cursor: pointer style to let the user know that this is clickable on mouse over.

You can also use jquery if you want to make it more elegant. But using JavaScript is the fastest and easy way.