How do I check if the value has change in DOM? I'm calling Ajax function to pull some data from database. I would like to blink or do some animation the that particular DIV if the new value has been pushed. So when "availability" changes do the animation only ONCE. Only to the DIV where the value has changed.
function getRealData() {
$.ajax({
url: 'test_api.php',
data: "",
dataType: 'json',
success: function (rows) {
var text = '';
for (var i in rows) {
var row = rows[i];
var availability = row[3];
var hostName = row[2];
var intranet = row[6];
var timeRespons = row[4];
//console.log(availability);
if (availability == 0){
var img = "img/tick.png";
}
if (availability == 1){
var img = "img/warning.png";
}
if (availability == 2){
var img = "img/alert.png";
}
text+= '<section class="square"><h3> ' + intranet + '</h3><img src='+img+' width="70" height="70" rel='+availability+' alt="warning"/><h4><img src="img/time_icon.png" width="20" height="20" alt="clock" class="clock" /> '+ timeRespons+'</h4>';
text += '</section>';
}
$("#journey").html(text);
}
});
}
setInterval(getRealData, 2000); //this refreshes data every 2seconds
getRealData(); //call the function to display data
The output is :
<div id="journey">
<div class="square>availability: 0 hostName: aaa intranet: ttt timeResponse:0.124</div>
<div class="square>availability: 0 hostName: qqq intranet: hhh timeResponse:0.064</div>
<div class="square>availability: 0 hostName: www intranet: nnn timeResponse:0.303</div>
<div class="square>availability: 0 hostName: rrr intranet: rrr timeResponse:0.019</div>
<div class="square>availability: 0 hostName: eee intranet: uuu timeResponse:0.025</div>
<div class="square>availability: 0 hostName: ggg intranet: ooo timeResponse:0.158</div>
</div>