Print with setInterval in the same place

Asked

Viewed 33 times

2

I need it when "filling..." is printed by setInterval, whether it’s exactly the same place as the first impression. It turns out it’s going down or forward. There is how to do this, print several times in the same place in 3 and 3 seconds without leaving there border?

var x = setInterval(function(){

$('div').append('<p id="demo1">Preenchendo...</p>')

}, 1000)
#demo{
    border: 1px solid black;
    height: 50px;
    width: 400px;
    text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body>


<span><h4>Espaço em branco</h4></span>
<div id="demo"></div>

</body>
</html>

1 answer

3


Comes instead of append use html. And for it to be every 3 seconds, just set the interval to 3000. Behold:

var x = setInterval(function() {

  $('div').html('<p id="demo1">Preenchendo...</p>')

}, 1000)
#demo {
  border: 1px solid black;
  height: 50px;
  width: 400px;
  text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>

<body>

  <span><h4>Espaço em branco</h4></span>
  <div id="demo"></div>

</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.