Home › Forums › JavaScript › Query: JS style.height IF statement › Re: Query: JS style.height IF statement
July 17, 2013 at 8:40 am
#143307
Participant
Okay. Now, I have no idea why this actually makes a difference but it does. Originally Paulie_D suggested that I used the JQuery toggleClass solution. It’s a great solution but I didn’t want to use JQuery. So, I figured I would change my JavaScript to change the className of the element rather than the style.height. And it now works on first click.
function expandNav() {
var nav = document.getElementById(“navBar”);
if (nav.className == “collapsed”) {
nav.className = “expanded”;}
else {
nav.className = “collapsed”;}
}