Richard Cheng Richard Cheng - 2 years ago 88
PHP Question

how to change multiple div every 5 seconds

I tried to update my posts every 5 seconds, like the time is updated, how many users commented and how many likes.
this is the code i tried so far

Some text1

<div id='poster' class='1'>
<input type='hidden' value='1' id='post_id'>
Some text1

<div id='poster' class='2'>
<input type='hidden' value='2' id='post_id'>
Some text2

<div id='poster' class='3'>
<input type='hidden' value='3' id='post_id'>
Some text3

<div id='poster' class='4'>
<input type='hidden' value='4' id='post_id'>
Some text4

in the body there is onload='refresh()'
here is what's in my java.js:

function refresh(){
var post_id = $("#post_id").val();

function refresh_post(post_id){

but it only updates the first div the rest remains the same

Answer Source

Use setinterval if you want to update post at every 5 second continuosly.

 $('input:hidden').each(function() {
 var post_id = $(this).attr('id');
}, 5000);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download