Try to search your question here, if you can't find : Ask Any Question Now ?

Empty div before append

HomeCategory: stackoverflowEmpty div before append
willson asked 2 weeks ago

I’m trying to append some html code with a loop into an html tag.
But every time that my loop refresh itself the code is appended a second time.
I tried to use $(#nodes).empty(); before the loop but with this method i get a blank screen.

This is the code snippet

   $(document).ready(function () {
 var interval = 10000;
 var refresh = function() {
 $.getJSON("https://tankionline.com/s/status.js",function(json){
   console.log("updated");
   var nodes = Object.keys(json.nodes).length;
    for (var i = 0; i < nodes; i++) {
      var num = i + 1;
      var main = 'main.c' + num;
      $("#nodes").append(`
        <tr>
          <th scope="row">${num}</th>
          <td> ${json.nodes[main].online} </td>
          <td> </td>
          <td> </td>
        </tr>
        `)
     }
 });
 setTimeout(function() {
   refresh();
     },
   interval);
     }
   refresh();

});

1 Answers
Best Answer
Amit answered 2 weeks ago
Your Answer

16 + 1 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com