Languages
[Edit]
EN

JavaScript - element padding size in Vanilla JS

11 points
Created by:
Imaan-Morin
1009

In this short article, we would like to show how to get the current padding of an element using JavaScript.

Presented below examples return padding in pixels - even different unit was used in styles.

Quick solution:

 

1. Current style property example

Edit

This approach allows to get current style value (even was assigned with selector).

2. Reusable code example

Edit

This approach organized the above code in a reusable function.

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join