Question: I'm trying to replace a div with another div every 30 seconds.

I have the below running however the div is not being replaced;

```
$( ".class1" ).setInterval(function() {
    $( this ).replaceWith('<div class="class2">54</div>');
} 3000);

```

What am I doing wrong?

Answer: 
Are you trying to change the text of the `span`?

```
 setInterval(changeText, 30000);
 function changeText(){
     if($(".class1").text() == "Hello World"){
          $(".class1").replaceWith("<div class='.class1'>My New Div</div>");
     }else{
         $(".class1").replaceWith("<div class='.class1'>Hello world</div>");
     }
 }

```
You can use `setInterval()` this way:

```js
$(function() {
  var origText = $('.class1').text(); // cache it here

  setInterval(function() {
    var newTxt = $('.class1').text(); // now get the current text in the div

    var txt = newTxt != 'Hello World' ? 'Hello World' : origText; // on condition change the text
    $('.class1').text(txt); // change the text here now.

  }, 3 * 1000); // replace it as 30 * 1000 = 30 seconds

});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class='class1'>Class 1</div>
```