Reputation: 11
I have a pop-up window (in Javascript) in which I would like to include a button hidden in an image.
So if the user clicks on the image the action should be performed. In HTML this is easy, but I don't know how to do this in Javascript. Thanks for any help.
What I know is how to do it with TEXT. This is how I do it:
document.write('<input type="button" value="F e r m e r" onClick=\'window.close()\' class="button" onmouseover="this.className=\'buttonon\'" onmouseout="this.className=\'button\'" style="width: 100px;">');
Upvotes: 1
Views: 85
Reputation: 375
You can just set background-image
of button in CSS as you're probably going to style it anyway.
document.write('<button type="button" class="image-button" onclick="myFunction()">')
function myFunction() {
console.log("I love Malamuts");
}
.image-button {
background-image: url("https://www.psy.pl/wp-content/uploads/2017/03/shutterstock_375206839-864x575.jpg");
background-size: cover;
width: 50vw;
height: 100vh;
}
Upvotes: 1