A jQuery inspired, lightweight JavaScript library intended for DOM manipulation.
This is the main function. You can pass it a string which represents either an HTML element or Class. It will return an instance of the DomNodeCollection class.
Every element wrapped in the $l
function will return an instance of this. This will allow to run the many functions of the API.
Receives an argument that will then be set as the innerHTML of each of the elements.
Will clear out the content the element.
Makes a simple ajax request. Receives a set of options and then does the call.
l.ajax = function (options) {
def = {
method: 'GET',
url: "",
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
data: {},
success: () => {},
error: () => {},
};
options = $l.extend(def, options);
const xhr = new XMLHttpRequest();
xhr.open(options.method, options.url, true);
xhr.onload = (e) => {
if (xhr.status > 199 && xhr.status < 300) {
options.success(JSON.parse(xhr.response));
} else {
options.error(JSON.parse(xhr.response));
}
};
xhr.send(JSON.stringify(options.data));
};
Receives an argument and then will add it as a child of the element.
Returns the attribute value of an element.
Adds a class to an element.
addClass(string) {
this.els.forEach( (attr) => {
return attr.classList.add(string);
});
}
Removes a class from an element.
Returns all the children of the element.
Returns the parent of the element.
Receives an argument and then returns all the descendants of the element that match it.
Removes the element from the DOM.
Adds an event handler to the element.
Removes an event handler from the element.