-2

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 %?

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

2 Answers2

1

You can do

Var pct = div.width * 1.0 / window.innerWidth
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
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