ahazha
Last Updated: February 25, 2016
·
50.17K
· jaysoo
571cd899248d35ac14382559520a570b

Force redraw on an element (jQuery)

This snippet can help in cases where the browser doesn't redraw an updated element properly.

$.fn.redraw = function(){
  $(this).each(function(){
    var redraw = this.offsetHeight;
  });
};

You'd then call the method like this:

$('.theElement').redraw();

More info can be found here on why it works: http://apmblog.compuware.com/2009/12/12/understanding-internet-explorer-rendering-behaviour/

2 Responses
Add your response

17759
0 oz05kbr1xwqhleauyv2nkqbtxe8clf7upqivkqchr2ntmwzrt1fwon aobhg hmb09juwpdo4mgu

Return the original jQuery collection to allow chaining. These comments don't allow code formatting, but:
$.fn.redraw = function() {
$(this).each(function() {
var redraw = this.offsetHeight;
});
return $(this);
};

over 1 year ago ·
17765
E83de6159de3ee4046f6510c66cf300b

Actually adding a return in front of $(this).each should do the trick for chaining.
$.fn.redraw = function(){
return $(this).each(function(){
var redraw = this.offsetHeight;
});
};

over 1 year ago ·