I want to get the present width of a div on the screen in percentage. When I use developer tools the width is shown in percentage but when I use $(this).width
, the width is shown in px
. Is there any way to get width in %?
Asked
Active
Viewed 412 times
-2

J.Con
- 4,101
- 4
- 36
- 64

Mayank Rana
- 7
- 2
-
no possible without calculating – LF00 May 16 '17 at 04:52
-
Why do you need it without calculating? If there is no function yet you would need to calculate it anyway – ImAtWar May 16 '17 at 04:53
-
What you have tried ? – Gammer May 16 '17 at 04:59
2 Answers
0
You'll have to calculate the width. The developer tools is doing all that behind the scenes, it's not actually present anywhere in the code unless you've put it in the CSS.
If it's just a percentage of the window width then you can easily do
($(this).width() / $(window).width()) * 100

Shai James
- 56
- 1
- 6