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/
Related protips:
Written by Jack Hsu
Related protips
2 Responses
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
·
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#