JavaScript offre un semplice modo per ottenere la larghezza esterna del box contenitore di un elemento compresi i margini.
La soluzione è la seguente:
'use strict';
const outerWidth = element => {
let width = element.offsetWidth;
const style = getComputedStyle(element);
width += parseInt(style.marginLeft,10) + parseInt(style.marginRight,10);
return width;
}