Skip to content

Instantly share code, notes, and snippets.

@andornagy
Last active December 15, 2015 15:19
Show Gist options
  • Save andornagy/5280752 to your computer and use it in GitHub Desktop.
Save andornagy/5280752 to your computer and use it in GitHub Desktop.
<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