Get width in pixels from element with style set with %?

后端 未结 7 1620
庸人自扰
庸人自扰 2021-01-31 00:57

I have this element:

I want to get it\'s width in pixels. I just tried this:

7条回答
  •  一生所求
    2021-01-31 01:49

    You can use offsetWidth. Refer to this post and question for more.

    console.log("width:" + document.getElementsByTagName("div")[0].offsetWidth + "px");
    div {border: 1px solid #F00;}

提交回复
热议问题