0

Basically what i have done is, i have made a web advert in after effects and i am looking to put it in HTML, If the user clicks on my ad, they get taken to a companion website of your choice. So i want the entire div that its in to be clickable and to make it link to another site. using javascript.



    <!-- Meta -->
    <meta charset="UTF-8" />
    <title>Bodymovin Demo</title>

    <!-- Styles-->
    <style>
        #bm{max-width: 970px:margin: 0 auto;}
     </style>

</head>
<body>

    <div id="bm"></div>





    <!-- Scripts -->
    <script src="lottie.js"></script>
    <script src="anim.js"></script>

The expected result is once you click on the web advert, you are directed to another site.

3

3 Answers 3

2

You can use the following Javascript:

<script>
    const adv_div = document.querySelector('#bm');
    const adv_url = 'https://www.google.com';
    adv_div.addEventListener(
        'click',
        () => {
            window.open(adv_url);
        }
    );
</script>

To change the cursor to a hand(pointer) when you hover on the element use this CSS:

#bm {
    cursor: pointer;
    max-width: 970px;
    margin: 0 auto;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Put it inside anchor tag

<a href="link"> 
    <div id="bm"></div> 
</a>

4 Comments

Somebody downvoted this answer, although this is perfectly fine and certainly better than relying on JavaScript.
I didn't downvote it but, i need java script as it is apart of the assignment to do it that way.
oh so its an assignment question!!!
Correct, i apologise for the confusion
0

Just create an onclick function on the div. Whenever there is a click inside the div the function will be called

function a()
{
console.log("Div clicked")
}
#bm {
  max-width: 970px:margin: 0 auto;
}
<div id="bm" onclick="a()">dfsfsdfsd sdfsdf sdfsd fsd fs dfsd
</div>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.