Last active
April 25, 2024 11:40
-
-
Save mortezasabihi/da421d9634342c530904f458105bc22c to your computer and use it in GitHub Desktop.
Javascript get element width without padding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wrapper = document.querySelector('#wrapper') | |
const wrapperComputedStyle = window.getComputedStyle(wrapper, null) | |
let wrapperWidth = wrapper.clientWidth | |
wrapperWidth -= | |
parseFloat(wrapperComputedStyle.paddingLeft) + | |
parseFloat(wrapperComputedStyle.paddingRight) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. As a function: