Search code examples
javascripthtmlcsswebweb-testing

How do I make a picture in my html website clickable?


I am trying to make a website, but Im kind of new to html and dont know how to make a picture clickable.

<div class="portfolio-img-background" style="background-image:url(Images/Dirt.jpg)">
                    
                </div>

This is how I am displaying the image, because I am later changing te style in css. So i would like to know what I need to add to make this image clickable. Thank you in advance for any help!

My entire code: https://pastebin.com/uiHH4vdB

Sorry for not specifying clickable correctly. What i need it to do is when I click the picture I need to open/ go to another html file.


Solution

  • If you want to stick with the Background-Solution you could do it the same way you handle the mouseover:

    porfolioItem.addEventListener('click', () => {
       console.log('click');
    })