Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Move element's class to parent element
* Usage example:
* $element.moveClassToParent('select-container');
*/
(function ($) {
"use strict";
// Create the defaults once
var pluginName = "moveClassToParent",
pluginObject = this;
// The actual plugin constructor
function Plugin(element) {
pluginObject = this;
/**
* The element the plugin was initiated on
* @type {jQuery}
*/
pluginObject.$wrapper = $(element);
}
function setOptions(options) {
pluginObject.options = options;
}
function moveSingleClass() {
var className = pluginObject.options;
if (pluginObject.$wrapper.hasClass(className)) {
pluginObject.$wrapper.parent().addClass(className);
pluginObject.$wrapper.removeClass(className);
}
}
$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this));
}
setOptions(options);
moveSingleClass();
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.