I was using goquery to parse HTML and I need to retrieve the height of these HTML elements but goquery doesn't have a jquery like .css() method? How can I achieve something like this?
1 Answers
You can't. Jquery runs in the browser where the HTML document is rendered and dimensions (such as height) are calculated by the browser, and are available to Javascript code.
Note that you can't access the rendered dimensions, because the document is not rendered. This doesn't mean you can't access the static attributes (e.g. height
) of the HTML tags, but there is absolutely no guarantee that this value will be the actual height of the element.
Goquery runs outside of your browser, where the HTML document is not rendered, and as such, dimensions are not available.
If you want to do it in Go, the HTML document must transfer this information to your Go app (server) e.g. via an AJAX call, or you must run your Go code in the browser, for which there are gopherjs and the Go web assembly target.

- 389,944
- 63
- 907
- 827
-
Thank you for your answer. Your answer is totally correct but, I was actually asking how can I achieve something like this with simple examples or libraries that might help – Sedat Can Yalçın Mar 01 '19 at 14:26
-
@SedatCanYalçın Asking how to do it without showing any attempt (and clear problem statement) is off-topic. Asking for 3rd party lib is also off-topic for StackOverflow. See: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – icza Mar 01 '19 at 14:27