I have a image. I would like to redirect to new webpage when someone clicks on the image. I know this will be possible by using anchor tag. But i want to do this without using anchor tag. Below my code.
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/368px-Google_2015_logo.svg.png" alt="Google image">
You can use JavaScript's Event Listener.
document.querySelector("#imgID").addEventListener("click", () => { window.location.href = "http://google.com"; });
You can use Jquery to redirect using on click event.
$( "#imageId" ).click(function() {
window.location.href = "RedirectPage";
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.