-2

I don't know how to make an HTML image clickable. Also, using Javascript, I want to know how to make a clickable HTML image redirect to another webpage when clicked. For example:

the HTML code of the image that I want to be clickable

Also, how to redirect to another webpage when the image is clicked. Like this:

This, when this is clicked I want it to redirect us to another webpage

Can someone please help me, I will appreciate any answers.

I tried doing this:

$('#imagefour').click(function() {
  window.location.href = "https://en.wikipedia.org/wiki/Assassination_Classroom";
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="">
  <img src="https://i.ytimg.com/vi/GY9FYJ-OG0I/maxresdefault.jpg" id="imagefour">
</a>

but nothing happened when I clicked the image, it didn't work. The school requires us to really use Javascript because it is the main goal of the project, thank you!!!

Bumhan Yu
  • 2,078
  • 1
  • 10
  • 20
mariella
  • 9
  • 1

1 Answers1

0

Put the click function inside document.ready

Raja M
  • 14
  • 1