• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Access to style properties in JS

CyberAP

Well-known member
#1
Is there any way to access style properties from JS?
For example I have a property 'loginBarCollapsedHeight' in Login Bar and I need to use it in my JS, how should I do this?
 

CyberAP

Well-known member
#3
Thanks! I know this should be working but my variable (loginBarCollapsedHeight) somehow is always undefined. Data attribute is present in loginBar.

Code:
var $loginBar = $('#loginBar');
var loginBarHeight = $loginBar.outerHeight();
var loginBarCollapsedHeight = $loginBar.data('loginBarCollapsedHeight');
loginBarCollapsedHeight.replace(/[^0-9]/g, '');
var loginBarMargin = loginBarHeight - loginBarCollapsedHeight;
 

Chris D

XenForo developer
Staff member
#4
data attributes must always be lower case.

That was one of the major breaking changes from old versions of jQuery to new.

It may be that. It must be lowercase in the HTML, e.g. data-loginbarcollapsedheight and also lower case in the JS, e.g. $loginBar.data('loginbarcollapsedheight');
 

CyberAP

Well-known member
#5
data attributes must always be lower case.

That was one of the major breaking changes from old versions of jQuery to new.

It may be that. It must be lowercase in the HTML, e.g. data-loginbarcollapsedheight and also lower case in the JS, e.g. $loginBar.data('loginbarcollapsedheight');
Figured it out the same time you posted :) Huge thanks for your help!