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);
};
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;
});
};
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside