Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery detect div (text/value) changes when Ajax pulls new data
    primarykey
    data
    text
    <p>Ok, I have now a big headache and trying to solve this for a few days but no success. I have an Ajax function that is within the setInterval and pulls in a new data from database every 2 seconds.</p> <p>The Ajax creates a 'div' with the dynamic data coming from database as some numbers. Now, what i would like to implement is that when the new data is pulled or the text or value in DOM changes I want that particular div to do some animation.</p> <p>Let's say it will change the background color to red and then reverse to the default color or the div border will flickr for three times, etc.. Somehow I cannot get this work. And i tried different Event listeners but no luck.</p> <p>Here's my code for Ajax:</p> <pre><code>$(document).ready(function () { //function the get data from database function getRealData() { $.ajax({ url: 'test_api.php', data: "", dataType: 'json', success: function (rows) { var text = ''; var text2 = ''; for (var i in rows) { var row = rows[i]; var timeRespons = row[4]; text+= '&lt;div class="square"&gt;&lt;h4&gt;Time Response: '+ timeRespons+'&lt;/h4&gt;'; text += '&lt;/div&gt;'; } $("#journey").html(text); } }); } //this refreshes data every 2seconds setInterval(getRealData, 2000); //call the function to display data getRealData(); }); </code></pre> <p>and here's the output:<img src="https://i.stack.imgur.com/c2vHq.png" alt="enter image description here"></p> <p>So let's say if the time response change, then make the background red for 2 seconds and then reverse it back. Many thanks for your help :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload