Getting div height with php and applying it to an image


as the title said i am trying to use php to get the height of a < div> element then with that value, applying to an image. This would actually shrink the image or stretch the image. As i am still new to coding, i searched online and what i found is only solution of doing it in javascript, which is something like this

DivHeight = document.getElementById("TheDiv").offsetHeight

but i couldn't find any that uses php to do so.

1/12/2010 9:47:05 AM

Accepted Answer

php is a server side language, which you cannot get the height of a div.

you may specify the image size by adding attributes

1/12/2010 9:49:55 AM

You want to set the image size AFTER the div object has been rendered as to fill said div object (or something to that effect), but the div object's size is variable. In such a scenario, you cannot use height: 100% because the parent object, the div object in this case, must have a definite value defined in the CSS code. Javascript is the only answer for this one.

Do this:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
        $('#theImagesId').css({"height":$(".theDivsId").height(), "width": $(".theDivsId").width()});

also you'll need to download this file that is referenced from jquery (the minified version will suffice):


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow