diff --git a/js/expand.js b/js/expand.js
index 1a719fad..a737ee7f 100644
--- a/js/expand.js
+++ b/js/expand.js
@@ -27,7 +27,8 @@ $(document).ready(function(){
success: function(data) {
var last_expanded = false;
$(data).find('div.post.reply').each(function() {
- if(thread.find('#' + $(this).attr('id')).length == 0) {
+ var post_in_doc = thread.find('#' + $(this).attr('id'));
+ if(post_in_doc.length == 0) {
if(last_expanded) {
$(this).addClass('expanded').insertAfter(last_expanded).before('
');
} else {
@@ -37,6 +38,9 @@ $(document).ready(function(){
$(document).trigger('new_post', this);
}
+ else {
+ last_expanded = post_in_doc;
+ }
});
$('' + _('Hide expanded replies') + '.')
.insertAfter(thread.find('span.omitted').css('display', 'none'))