diff --git a/src/helpers/element.js b/src/helpers/element.js index c033e08f..d2bdba57 100644 --- a/src/helpers/element.js +++ b/src/helpers/element.js @@ -13,9 +13,11 @@ Handlebars.registerHelper('element', function(element, options) { // IE will lose a reference to the elements if view.el.innerHTML = ''; // If they are removed one by one the references are not lost Thorax.View.on('before:append', function() { - _.each(this._elementsByCid, function(element, cid) { - $(element).remove(); - }); + if (this._renderCount > 0) { + _.each(this._elementsByCid, function(element, cid) { + $(element).remove(); + }); + } }); Thorax.View.on('append', function(scope, callback) { diff --git a/src/helpers/view.js b/src/helpers/view.js index 61283efb..51f102c7 100644 --- a/src/helpers/view.js +++ b/src/helpers/view.js @@ -23,6 +23,16 @@ Handlebars.registerHelper('view', function(view, options) { return new Handlebars.SafeString(Thorax.Util.tag(htmlAttributes, undefined, expandTokens ? this : null)); }); +// IE will lose a reference to the elements if view.el.innerHTML = ''; +// If they are removed one by one the references are not lost +Thorax.View.on('before:append', function() { + if (this._renderCount > 0) { + _.each(this.children, function(child, cid) { + child.$el.remove(); + }); + } +}); + Thorax.View.on('append', function(scope, callback) { (scope || this.$el).find('[' + viewPlaceholderAttributeName + ']').forEach(function(el) { var placeholderId = el.getAttribute(viewPlaceholderAttributeName),