property
for given tagName
:const getDefaultProperty = function (tagName, property) {// Create new elementconst ele = document.createElement(tagName);// Append to the bodydocument.body.appendChild(ele);// Get the styles of new elementconst styles = window.getComputedStyle(ele);// Get the value of propertyconst value = styles.getPropertyValue(property);// Remove the elementdocument.body.removeChild(ele);// Return the value of propertyreturn value;};
...const styles = window.getComputedStyle(ele);document.body.removeChild(ele);// Always return "" because the element is already// removed from the documentreturn styles.getPropertyValue(property);
div
tag:getDefaultProperty('div', 'font-size');// OrgetDefaultProperty('div', 'fontSize');