Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  136] [ 4]  / answers: 1 / hits: 21716  / 12 Years ago, thu, may 3, 2012, 12:00:00

I have the following script



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


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


More From » jquery

 Answers
50

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.



Sources:




[#85834] Tuesday, May 1, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;