The jQuery library is created for less code writing. You can write less and get more using jQuery. There are a lot of readymade methods in the jQuery library. A loader image can be inside a div block or outside a div block, you can display or show using the jQuery() show method. The show() method is used to display kinds of modules using the id or class. We can easily display any image, div block, span, paragraph, popup, etc using the show() method in jQuery.
If you want to display a loader image or any image then use the show() method in jQuery-
For example-
$("#loader").show();
loader - loader is an id of a loader gif image.
show() - show() is a jQuery readymade method.
You can use loader image class instead of id.
For example -
$(".loader").show();
Use the dot (.) symbol.
How to show loader image on button click -
It's a very interesting topic in jQuery.
You can execute the same show() function with a button click.
<script type="text/javascript">
$(document).ready(function(){
$("#my_btn").click(function()
{
$("#loader").show();
});
});
</script>
my_btn - Submit button id.
As you know in JavaScript, we can create a function and execute an onClick event.
You can execute showloader() user-defined function onClick event.
<button type="button" id="submit_form" onClick="showloader();"> Submit</button>
The function will execute and display the loader image.