Why does span tag under div disappear when jQuery refreshes div data

$(document).ready(function() {
  setInterval(function() {
    $.get("temp.php", function(temp) {
      $("deneme span").html(temp);
      $("#deneme").html(temp);

    });
  }, 3000);
});
      

<div class="container">
  <div class="de">
    <div class="den">
      <div class="dene">
        <div class="denem">
          <div class="deneme" id="deneme">
            <span></span><strong>&deg</strong>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

</center>
      

Run codeHide result


+3


source to share


2 answers


This is because it .html()

replaces the HTML inside your div.

So with, $("deneme span").html(temp);

you try to fill a range, but then with, $("#deneme").html(temp);

you remove all content and replace it with temp

.



I suggest you use .append()

to add something to a div.

+3


source


Just a shot in the dark: (more code will help)

$("deneme span").html(temp);

      

I noticed that you have included the tag <span>

above.



Remove the tag <span>

i.e. $("deneme")

if you don't want this to be done with.html(temp);

After you've done this, try adding display:inline-block;

to the element <span>

for more stability to prevent the position from moving when the element is moved higher.

... html ()

+1


source







All Articles