Skip to content
Recommend our themes and earn 30% of our share of every sale you bring. Free to join.Earn by recommending our themes Become an affiliate

How to make div clickable

Updated 07 Feb 2019 29 downloads
It can be done using jQuery click event and window.location.href function. Click event will be fired when user click on div then redirect function will redirect the page to specified link.

Source code

<!DOCTYPE html>
<html>
    <head>
        <title>How to make div clickable - jQuery | MG Technologies</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="jquery-1.js" type="text/javascript"></script>
        <script>
            $(document).ready(function(){
                $(".clickable").click(function(){
                    alert("Div is clicked! Now it will redirect to home page");
                    window.location.href = "https://www.mgtechnologies.co.in/";
                });
            });
        </script>
    </head>
    <body>
        <h2>Clickable div using jQuery</h2>
        <div class="clickable">I'm a DIV linked with home page. Click me to see that.</div>
    </body>
</html>

See it live

More code answers

Comments

Log in to leave a comment.