admin管理员组文章数量:1405170
i am trying to figure this out:
i have some html and php:
<div class="main" style="height: 800px">
<div class="head" style="height: 300px"</div>
<div class="container">
<?php
for ($i=0; $i<=$size;$i++){
echo "<div style="/"height: 20px;/">line $i</div>";
}
?>
</div>
</div>
now, what i am trying to do is to find the height of the .container
div and apply it to $size
if the .container
height is 100 then i will do something like: $size = 100 / 20
or something similar.
The issue is that even if i find the div height it is still on the client side and i might have to do some ajax.
Another problem is that if there is no content in the .container
usually there is no height.
in this case i could force the size of .container
to be 800 - 300
but i don't allays know other sizes from different block elements on the page.
i hope i am not to confuse with this question.
any ideas?
Thanks
i am trying to figure this out:
i have some html and php:
<div class="main" style="height: 800px">
<div class="head" style="height: 300px"</div>
<div class="container">
<?php
for ($i=0; $i<=$size;$i++){
echo "<div style="/"height: 20px;/">line $i</div>";
}
?>
</div>
</div>
now, what i am trying to do is to find the height of the .container
div and apply it to $size
if the .container
height is 100 then i will do something like: $size = 100 / 20
or something similar.
The issue is that even if i find the div height it is still on the client side and i might have to do some ajax.
Another problem is that if there is no content in the .container
usually there is no height.
in this case i could force the size of .container
to be 800 - 300
but i don't allays know other sizes from different block elements on the page.
i hope i am not to confuse with this question.
any ideas?
Thanks
Share Improve this question asked Jan 10, 2012 at 18:50 PatrioticcowPatrioticcow 27.1k76 gold badges221 silver badges340 bronze badges 1- 2 You can't make operation with php on client side. It muts be parsed on the server side. Javascript will do the trick. – Michael Sazonov Commented Jan 10, 2012 at 18:53
1 Answer
Reset to default 7Description
You can use jQuery's height()
and width()
method to get the size.
Check out the sample and jsFiddle Demonstration
Sample
html
<div class="container">
MyContent<br><br>
</div>
jQuery
alert($(".container").height())
alert($(".container").width())
More Information
- jsFiddle Demonstration
- jQuery.height()
- jQuery.width()
本文标签: phphow to find the size of a div in javascriptStack Overflow
版权声明:本文标题:php - how to find the size of a div in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744886126a2630496.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论