Currently the posts are filtered by: 2011-01-05
Reset this filter to see all posts.

Category: Javascript
Date: 2011-01-05 23:35

Fix jQuery .replaceWith() method to perform in IE8

This article applies to jQuery 1.4.4

The jQuery .replaceWith() method replaces a DOM-element and all of its children by another DOM-element. This function is ideal for use in Ajax applications.

The .replaceWith() method however internally uses the jQuery .remove() method which in Internet Explorer can be dramatically slow. There is a tric however to improve this performance radically by emptying the DOM-element first before removing it. 

It enhanced my performance in IE at least 10 times!

Here's the line:

jQuery(selector).empty().replaceWith(newContent);