Last active
December 15, 2015 15:19
-
-
Save andornagy/5280752 to your computer and use it in GitHub Desktop.
This file contains 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
<script type="text/javascript" charset="utf-8"> | |
var newClass = document.getElementById('classes'); // This is the class name of your dropdown menu with the new classes | |
var div = document.getElementById('div'); // Is the ID of the element you want to change class on. | |
addEvent(newClass, 'change', function() { | |
div.className = newClass.value; | |
}); | |
// Based on the lessons from Nettuts | |
function addEvent(obj, evt, fn) { | |
evt = evt.replace('on', ''); | |
if( obj.attachEvent ) | |
obj.attachEvent('on' + evt, fn); | |
else | |
obj.addEventListener(evt, fn, false); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment