title: How to get each post's id on my page?
body: <p>I am trying to send post id in js. I can send the first post id but how can I  send  each post's id. inspect element looks like this </p>
  
  <pre><code>&lt;div  data-id="post_1"&gt;&lt;/div&gt;
  &lt;div  data-id="post_2"&gt;&lt;/div&gt;
  &lt;div  data-id="post_3"&gt;&lt;/div&gt;
  
  
  &lt;script type="text/javascript" &gt;
   function ajax(){
  
      var req = new XMLHttpRequest();
  
      req.onreadystatechange = function(){
  
      if(req.readyState == 4 &amp;&amp; req.status == 200){
  
      document.querySelector('[data-id=post_1]').innerHTML = req.responseText;
      } 
      }
      req.open('GET','chat.php?id=1&gt;',true); 
      req.send();
  
      }
      setInterval(function(){ajax()},1000);
  
  
  &lt;/script&gt;   
  </code></pre>
  
  <p>here is the code </p>
  
  <pre><code>&lt;div  data-id="post_&lt;?php echo $post_id;?&gt;"&gt;&lt;/div&gt;
  
  
  
  &lt;script type="text/javascript" &gt;
   function ajax(){
  
      var req = new XMLHttpRequest();
  
      req.onreadystatechange = function(){
  
      if(req.readyState == 4 &amp;&amp; req.status == 200){
  
      document.querySelector('[data-id=post_&lt;?=$post_id?&gt;]').innerHTML = req.responseText;
      } 
      }
      req.open('GET','chat.php?id=&lt;?=$post_id?&gt;',true); 
      req.send();
  
      }
      setInterval(function(){ajax()},1000);
  
  
  &lt;/script&gt;    
  </code></pre>
  
  <p>All the posts are on the same page. But I am able to get only one post's id. How can I get id  <code>post_2</code> and <code>post_3</code>  in js? </p>
  
  <p>The js shows comment for each post. Only first post is showing comments cause js is getting only the first post's id. Rest are not showing anything. </p>
  
  <p>How can I do the same for every post ?   </p>