9

I wonder if I could get a DOM element's actual width and coordinates, as I can get using .clientWidth / .offsetWidth from within the browser.

Does jsdom has browser rendering capabilities in order to get this data?

If not, how can I get this within node.js server?

Thanks!

tomericco
  • 1,544
  • 3
  • 19
  • 30
  • This has nothing to do with node.js. Node.js executes on an application / web server, not the client's browser. I think jQuery has functions to get you the computed width and height of an element. – Brandon Nov 11 '13 at 19:46
  • 1
    @Brandon: node has many libraries that emulate the DOM API on the server; jsdom is one of them. – josh3736 Nov 11 '13 at 21:50
  • 1
    Brandon, can you write some of them? This is what I'm looking for. – tomericco Nov 13 '13 at 17:57

1 Answers1

16

JSDOM is strictly a DOM API emulation library. It does not attempt to actually render a document, which is necessary to compute element size and position.

You may want to look at PhantomJS. It is a full WebKit renderer with a JavaScript API. It is entirely separate from node, so you either need to write a utility script using Phantom's API, or use a npm module that lets you control Phantom from node.

josh3736
  • 139,160
  • 33
  • 216
  • 263
  • I'm aware of this unreliable integration between them. I'm looking for official solutions. If it's not possible, I will mark this as an answer. – tomericco Nov 13 '13 at 17:58