Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Query: JS style.height IF statement Re: Query: JS style.height IF statement

#143307
deldalton
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”;}
}