Skip to content

Instantly share code, notes, and snippets.

@EliJDonahue
Created December 1, 2016 20:23
Show Gist options
  • Select an option

  • Save EliJDonahue/0a858c9291cecbfd90bf26dad9858cc5 to your computer and use it in GitHub Desktop.

Select an option

Save EliJDonahue/0a858c9291cecbfd90bf26dad9858cc5 to your computer and use it in GitHub Desktop.
Add a custom CSS class to a collection of elements
////////////////////// Helpful functions ///////////////////////////////////
// appends a value to an attribute for all elements in a collection
// can be used to append class name
appendAttributeOnAll = function(els, attrName, attrVal)
{
for (var i=0; i < els.length; i++)
{
var curr = els[i].getAttribute(attrName);
els[i].setAttribute(attrName, curr + ' ' + attrVal);
}
};
////////////////////// Override default styles /////////////////////////////
// inline label style
appendAttributeOnAll(labels,'class','my_label');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment