Why won't Jquery test the CSS properly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why won't Jquery test the CSS properly?

I'm testing to see if the hiddenMenu left css is -100%, if so set to 0%. And do the opposite if it's 0%, ultimately making a sidenav. For some reason when testing document.querySelector(".hiddenMenu").style.left == "-100%", the if statement won't trigger. How can I test left css? Sorry about the readability on mobile, line wrap did something bad for once https://code.sololearn.com/W2IzqJBd8sQ3/?ref=app

30th Jul 2020, 5:22 PM
Clueless Coder
Clueless Coder - avatar
2 Answers
+ 2
You can't access css style that way ,it will return nothing unless it's set to some value,to get css value you need to use getComputedStyle(document.querySelector(".hiddenmenu")).left which returns value in pixels which for -100% is -360px through jQuery you can get it much easily, menu.css("left"));
30th Jul 2020, 5:56 PM
Abhay
Abhay - avatar
+ 1
Abhay Thanks, never heard of that function before
30th Jul 2020, 6:01 PM
Clueless Coder
Clueless Coder - avatar