user3663922 user3663922 - 1 month ago 5
jQuery Question

How to delay the text function in jQuery

I'm trying to change the text present in a div to another text by using text() function in jQuery. It is working fine but it is too fast. Is there anyway to delay this text() function so that I can view the change properly. Here's the code.Please take a look at it. Thanks in advance :)



$('.main .title').text("Changed title!");
$('.main .description').text("Changed Description");

.main {
background-color: orange;
color: white;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main">
<div class="title">
<p>This title text should be changed</p>
</div>
<div class="description">
<p>This description should als be changed</p>
</div>
</div>




Answer

You can set Time out function for delay

< script type="text/javascript">

setTimeout(function () {

            $('.main .title').text("Changed title!");
            $('.main .description').text("Changed Description");
        }, 1000);

Comments