Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addClass: function (newClass) {
- this.elements.forEach((element, index) => {
- if (typeof newClass === 'function') {
- const cssClasses = newClass.call(element, index, element.className);
- $(element).addClass(cssClasses);
- }
- })
- }
- return this;
- },
- append: function (newChild) {
- if (typeof newChild == 'string') {
- if (this.elements.length > 1) {
- this.elements.forEach(element =>
- element.innerHTML = newChild);
- } else {
- this.elements[0].innerHTML = newChild;
- }
- } else {
- this.elements.forEach((element, index) => {
- if (newChild.hasOwnProperty('elements')) {
- element.appendChild(newChild.elements[0].cloneNode(true))
- } else {
- element.appendChild(newChild.cloneNode(true))
- }
- });
- }
- return this;
- },
- attr: function (attr, args) {
- if (arguments.length == 1) {
- return this.elements[0].getAttribute(attr);
- } else {
- this.elements.forEach(element => {
- for (let i = 0; i < arguments.length; i += 2) {
- element.setAttribute(arguments[i], arguments[i + 1]);
- }
- });
- }
- return this;
- },
- children : function () {
- if (typeof this.elements.length == 'undefined') {
- this.elements.children;
- }
- return this.elements[0].children;
- };
- html : function(arg) {
- if (!arg) return this.elements[0].innerHTML;
- if (typeof(arg) === "string") this.each(function (index, item) { item.innerHTML = arg; });
- if (typeof(arg) === "function") this.each(function (index, item) {item.innerHTML = arg(index); });
- return this;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement