alexandra siracevska alexandra siracevska - 11 months ago 119
Javascript Question

plain javascript to jquery - clientHeight

I have the following script

var doc = win.document;
if (doc.querySelector && doc.addEventListener) {
var toggler = doc.querySelector('.toggle-menu')
var menu = doc.querySelector('.main-nav ul'); = '0px';
toggler.addEventListener('click',function(e) {
if ( == '0px') { = 'auto';
if (menu.clientHeight != 0) { = menu.clientHeight+'px';
} else { = '0px';

What will be the jQuery version of that script, since i can't find a jQuery equivalent to clientHeight.

Answer Source

clientHeight is not a jQuery property. It was introduced in Internet Explorer, but isn't part of the W3C specifications. It looks like it is only supported in Firefox and Internet Explorer. I've just tested that it works in the latest version of Chrome, though. Not sure if results are standard across browsers, though the link I posted below suggests no.

Also, Mozilla suggests the following formula to be used in place for browsers that don't support it:

clientHeight can be calculated as CSS height + CSS padding - height of horizontal scrollbar (if present).

I'm assuming that is the scrollbar of the element itself, not the entire browser window, unless the element takes up the entire window.