I have some content that is loaded from a XML file with XMLHttpRequest:
<div uid="29710" >
content....
</div>
<div uid="19291" >
content....
</div>
<div uid="099181" >
content....
</div>
The code used to get the content:
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","notes.xml",false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
var x = xmlDoc.getElementsByTagName("noteboard");
var newHTML = "";
for (i=0;i<x.length;i++) {
newHTML += "<div><div uid='"+ x[i].getAttribute('uid')+"'>"
+ x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue
+ "<br>"+ x[i].getElementsByTagName("message")[0].childNodes[0].nodeValue
+"</div></div>";
}
document.querySelector('#panel').innerHTML += newHTML;
The content is updated every 3 seconds, but the problem starts when the old content is repeated and piled up, as well as the new content. Also, the UID attribute value is loaded from the same XML file as the content - so all the new repeated content has the same UID as the old repeated content.
If I am not clear enough, this is the sort of thing that is happening:
<div uid="19291">Old Content</div>
<div uid="77191">New Content</div>
<div uid="19291">Old Content</div>
<div uid="19291">Old Content</div>
<div uid="21503">New Content</div>
So how would you remove all the divs that have the same UID value as each other, except for the original one ?