I'm building a small chat application to learn a bit about jquery and AJAX. It's all working great, but at the moment, the chatbox is grabbing the HTML of log.html on an interval with the following code:
function loadLog(){
$.ajax({
url: "log.html",
cache: false,
success: function(html){
$(".chatbox").html(html); //Insert chat log into the #chatbox div
},
});
}
Now if a user is trying to copy a line, it's bugging out because the html is getting refreshed every few seconds. So I would like to build a check that remembers the last known message and compares it to the last message in the log. If they don't match (a new message has appeared), only then will the browser refresh the html in the chatbox.
I'm quite new to AJAX and Jquery so I would like to ask you guys the following question: What would be the best way of comparing the last message in log.html and the last div in the chatbox div?
My theory would be to
success: function(html){
$(html).find(last(div));
},
But i don't exactly know how to get the value of the last div.
I hope I explained the question well enough. Also, any ideas are welcome :)
P.S. This is an example of a line in log.html
<div class='msgln'>(4:40 PM) <b>Jeroen</b>: Welcome<br></div>