JSFiddle - React, Tailwind, and code Playground
JavaScript
// Function to get doc width by measuring a 100% width div
var getDocWidth = function() {
// Create div
var e = jQuery('<div></div>');
// Set width
e.css({
'position':'absolute',
'top':'0',
'left':'0',
'width':'100%'
})
// Append to body
jQuery('body').append(e);
// Get width
var w = e.innerWidth();
// Remove
e.remove();
// Return
return w;
};
// Add a div so scrollbars appear
var e = jQuery('<div>---</div>')
// Set its style
e.css({
'position':'absolute',
'top':'0',
'left':'0',
'height':(jQuery(document).height() + 20) + 'px'
});
// Append it to the body
jQuery('body').append(e);
// Append details to the body
jQuery('body').append(
'<p>Width:</p>' +
'<p>document object says: ' + jQuery(document).width() + 'px</p>' +
'<p>element width 100% says: ' + getDocWidth() + 'px</p>'
);