learner learner - 1 month ago 9
PHP Question

Can we measure height of a div using php?

Can we measure height of a div using php?

Answer Source

This is not possible at all: PHP serves HTML code. The browser renders it. Only after it is rendered, can height be determined reliably. Different browsers may end up with different heights. Different user settings (like font size) may end up with different heights.

The only way to find out an element's height is using JavaScript which runs in the browser. You can theoretically send the results back to a separate PHP script using Ajax, but I doubt that'll make much sense.

You could use jQuery's .height() like so:

var height = $("#elementID").height();

(there are native JavaScript approaches to this as well, but they tend to be a bit long and complicated.)