3 ms·
They cause immediate reflow only if the DOM is dirty. In both cases it'd be a maximum of 1. This'd be 2: element.textContent = 'omg'; var w = element.
by paulirish 11y ago
They cause immediate reflow only if the DOM is dirty. In both cases it'd be a maximum of 1.
This'd be 2:
element.textContent = 'omg';
var w = element.clientWidth;
elem.classList.add('ok');
var h = element.clientHeight;
- jffry 11y agoAnd it's especially bad if you interleave them all: var heights = lotsOfElements.map(function(el){ el.classList.add('ok'); return el.clientHeight; }); Better is to batch the DOM updates and reads, where you can: lotsOfElements.forEach(function(el){ el.classList.add('ok'); }); var heights = lotsOfElements.map(function(el){ return el.clientHeight; });