Last active
December 16, 2015 19:19
-
-
Save stephanie-walter/5484317 to your computer and use it in GitHub Desktop.
Toggle Class in RAW JavaScript when element is clicked (for menu purpose here)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function changeClass(elem,className1,className2){ | |
elem.className = (elem.className == className1)?className2:className1; | |
} | |
document.getElementById('menutoggle').onclick = function() { | |
changeClass(this, 'navtoogle active', 'navtoogle'); | |
} | |
// Many thanks to https://twitter.com/Martel_Louis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's ok if we only have one class in className.
To be more accurate :
Fonctionne sous Firefox -> http://jsfiddle.net/5xBzF/