I have a button and on click on it the text changes and I want to include Image with it and don’t know how, I’m new with JavaScript, help please!
<input onclick="change()" type="button" id="pay-btn" value="Click here to check" />
function change()
{
document.getElementById("pay-btn").value="'https://i.stack.imgur.com/kOnzy.gif' please wait...";
}
I tried to search on StackOverflow and Google but don’t find a way to do this.
2
Answers
You can do it like below
the data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs= is an empty image and you can change it with the opposite image of loading
and js
The scenario is:
EDIT
you can do it by same way
add this line into your function
As requested, an example using
addEventListener
. The main differences are that the JavaScript logic stays within the JavaScript files. Besides that, you can only add oneonclick
listener, but multiple listeners withaddEventListener
.Next to that it shows an example of how to create an image within JavaScript, add a
src
andalt
to it, before appending it to the button. If you’d inspect the button with your browser tools, you’ll see that the HTML has changed.