Hello everyone I am working with javascript, Right now i want to display "loader-image" after click on button, so how can i do this ?
Here is my image url
https://xxxxxxxxx/wp-content/uploads/2023/04/Loading_icon.gif
And here is my current code
jQuery('#double_click_submit').click(function(event) {
//want to display loader (url menitoned above)
});
3
Answers
You can hide the loader by default and show it whenever you press on the button like this:
if you want to show it at the top of the page ( I used body but if you want to insert at the beginning of any class or id, you can use that instead)
To display a loader image after clicking on the button using jQuery, you can follow these steps:
Select the image element and store it in a variable:
var loaderImage = $(”, {
src: ‘https://xxxxxxxxx/wp-content/uploads/2023/04/Loading_icon.gif’
});
Append the loader image to the container where you want to display it:
jQuery(‘#container’).append(loaderImage);
Replace #container with the ID or class of the element where you want to display the loader image.
3.Add the loader image to the click event handler for the button:
This will add the loader image to the container when the button is clicked.
Note: If you want to hide the loader image once the button click action is complete, you can use the hide() method to hide the image: