Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigned width in percentage but want to get it in pixels

Tags:

html

jquery

css

.test {    border: 1px solid;    cursor: pointer;    height: 10px;    position: relative;    width: 100%;  }
<div id="test1" class="test"></div>

I have displayed my HTML id and its CSS. Now when I am doing $('#test').width() I am getting 100. I want its width in pixels (not in %).

Can anyone tell how to get its width in pixels?

like image 385
Denzz Avatar asked Jun 25 '13 19:06

Denzz


1 Answers

One of options can be too, that parent element is not visible. Here is example: http://jsfiddle.net/nDMM3/

You can see, that jQuery return width = 100 (like 100%)

.test {     border: 1px solid;     cursor: pointer;     height: 10px;     position: relative;     width: 100%;     display:none; }  #test2{    width:100%; }  <div id="test1" class="test">    <div id="test2">       Hello    </div>      </div>      alert($('#test2').width()); 
like image 83
Jan Jarčík Avatar answered Oct 07 '22 19:10

Jan Jarčík