陈家泽
陈家泽

Reputation: 115

Get the Coordinates of DOM node in HTML

How can we can the coordinates of the DOM Node in a HTML File?

Javascript offsetWidth,offsetHeight can do the work.

But I need a Browser to render the HTML file.

Can I finish the work by only use commands?

Upvotes: 1

Views: 204

Answers (1)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201876

HTML elements as such have no coordinates, and the DOM exists in practice only after some program has parsed the HTML and constructed the DOM. Even though you could use non-browser programs to do the parsing and DOM construction, the formatting of a document (in addition to parsing and DOM construction) is the job of a browser. And formatting is needed to allocate coordinates to elements.

Thus, while you can use different programs to do what you are after, they are programs that are normally called browsers.

Upvotes: 2

Related Questions