Wednesday, June 11, 2014

Toggle Menu Javascript

Javascript code that will allow an element to be turned into a toggle menu.

// JavaScript Document

var originalNavClasses;

function toggleNav() {
    var elem = document.getElementById('navigation_list');
    var classes = elem.className;
    if (originalNavClasses === undefined) {
        originalNavClasses = classes;
    }
    elem.className = /expanded/.test(classes) ? originalNavClasses : originalNavClasses + ' expanded';
}

No comments:

Post a Comment