user3560322
user3560322

Reputation: 55

How to display an image for a second when we click on a div?

I am using jquerymbiles 1.4.2.I want my image to be display for a 5 seconds when we click on a div. The code which i am using in my page is here click

<script>
 $(document).ready(function () {
$(".hr").click(function(){
   $("#imgstate").show();
});
});
</script>

The above code displays the image when we click n a div but i dm not getting how to hide it after a 5 seconds please help me in this

Upvotes: 0

Views: 54

Answers (1)

Felix
Felix

Reputation: 38102

You can use .delay():

$(document).ready(function () {
    $(".hr").click(function () {
        $("#imgstate").show().delay(5000).hide();
    });
});

Try to use .setTimeout() here:

$(document).ready(function () {
    $(".hr").click(function () {
        $("#imgstate").show();
        setTimeout(function() {
            $("#imgstate").hide();
        }, 5000);
    });
});

Fiddle Demo

Upvotes: 1

Related Questions